1fab63cc4SDoug Rabson.\" -*- nroff -*- 2fab63cc4SDoug Rabson.\" 3fab63cc4SDoug Rabson.\" Copyright (c) 1996 Doug Rabson 4fab63cc4SDoug Rabson.\" 5fab63cc4SDoug Rabson.\" All rights reserved. 6fab63cc4SDoug Rabson.\" 7fab63cc4SDoug Rabson.\" This program is free software. 8fab63cc4SDoug Rabson.\" 9fab63cc4SDoug Rabson.\" Redistribution and use in source and binary forms, with or without 10fab63cc4SDoug Rabson.\" modification, are permitted provided that the following conditions 11fab63cc4SDoug Rabson.\" are met: 12fab63cc4SDoug Rabson.\" 1. Redistributions of source code must retain the above copyright 13fab63cc4SDoug Rabson.\" notice, this list of conditions and the following disclaimer. 14fab63cc4SDoug Rabson.\" 2. Redistributions in binary form must reproduce the above copyright 15fab63cc4SDoug Rabson.\" notice, this list of conditions and the following disclaimer in the 16fab63cc4SDoug Rabson.\" documentation and/or other materials provided with the distribution. 17fab63cc4SDoug Rabson.\" 18fab63cc4SDoug Rabson.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 19fab63cc4SDoug Rabson.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20fab63cc4SDoug Rabson.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21fab63cc4SDoug Rabson.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 22fab63cc4SDoug Rabson.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23fab63cc4SDoug Rabson.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24fab63cc4SDoug Rabson.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25fab63cc4SDoug Rabson.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26fab63cc4SDoug Rabson.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27fab63cc4SDoug Rabson.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28fab63cc4SDoug Rabson.\" 297f3dea24SPeter Wemm.\" $FreeBSD$ 30fab63cc4SDoug Rabson.\" 31fab63cc4SDoug Rabson.Dd July 24, 1996 32fab63cc4SDoug Rabson.Os 33fab63cc4SDoug Rabson.Dt VOP_LINK 9 34fab63cc4SDoug Rabson.Sh NAME 35fab63cc4SDoug Rabson.Nm VOP_LINK 36fab63cc4SDoug Rabson.Nd create a new name for a file 37fab63cc4SDoug Rabson.Sh SYNOPSIS 382e14815bSBruce Evans.Fd #include <sys/param.h> 39fab63cc4SDoug Rabson.Fd #include <sys/vnode.h> 40fab63cc4SDoug Rabson.Ft int 41fab63cc4SDoug Rabson.Fn VOP_LINK "struct vnode *dvp" "struct vnode *vp" "struct componentname *cnp" 42fab63cc4SDoug Rabson.Sh DESCRIPTION 43fab63cc4SDoug RabsonThis links a new name in the specified directory to an existing file. 44fab63cc4SDoug Rabson.Pp 45fab63cc4SDoug RabsonIts arguments are: 463136363fSRuslan Ermilov.Bl -tag -width 8n 47fab63cc4SDoug Rabson.It Ar dvp 48fab63cc4SDoug Rabsonthe vnode of the directory 493ac84fedSMatthew Dillon.It Ar vp 50fab63cc4SDoug Rabsonthe vnode of the file to be linked 51fab63cc4SDoug Rabson.It Ar cnp 52fab63cc4SDoug Rabsonpathname information about the file 53fab63cc4SDoug Rabson.El 54fab63cc4SDoug Rabson.Pp 553ac84fedSMatthew DillonThe pathname info must be released on exit. The directory and 563ac84fedSMatthew Dillonfile vnodes should NOT be released on exit. 57fab63cc4SDoug Rabson.Sh LOCKS 58fab63cc4SDoug RabsonThe directory, 59fab63cc4SDoug Rabson.Fa dvp 60fe11eb74SMatthew Dillonis locked on entry and should remain locked on return. 61fab63cc4SDoug RabsonThe file 62fab63cc4SDoug Rabson.Fa vp 6337af2883SMatthew Dillonis not locked on entry and should remain that way on return. 6437af2883SMatthew DillonIf your VOP code locks 6537af2883SMatthew Dillon.Fa vp , 6637af2883SMatthew Dillonit must be sure to unlock prior to returning. 67fab63cc4SDoug Rabson.Sh RETURN VALUES 68fab63cc4SDoug RabsonZero is returned if the file was linked successfully, otherwise an 69fab63cc4SDoug Rabsonerror is returned. 70fab63cc4SDoug Rabson.Sh PSEUDOCODE 71fab63cc4SDoug Rabson.Bd -literal 72fab63cc4SDoug Rabsonint 73fab63cc4SDoug Rabsonvop_link(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) 74fab63cc4SDoug Rabson{ 75fab63cc4SDoug Rabson int error = 0; 76fab63cc4SDoug Rabson 77fab63cc4SDoug Rabson if (vp->v_mount != dvp->v_mount) { 78fab63cc4SDoug Rabson VOP_ABORTOP(dvp, cnp); 79fab63cc4SDoug Rabson error = EXDEV; 80fab63cc4SDoug Rabson goto out2; 81fab63cc4SDoug Rabson } 82fab63cc4SDoug Rabson if (vp != dvp && (error = VOP_LOCK(vp))) { 83fab63cc4SDoug Rabson VOP_ABORTOP(dvp, cnp); 84fab63cc4SDoug Rabson goto out2; 85fab63cc4SDoug Rabson } 86fab63cc4SDoug Rabson 87c20b4df6SMatthew Dillon /* 88c20b4df6SMatthew Dillon * now that we've locked vp, we have to use out1 instead of out2 89c20b4df6SMatthew Dillon */ 90c20b4df6SMatthew Dillon 91fab63cc4SDoug Rabson if (vp would have too many links) { 92fab63cc4SDoug Rabson VOP_ABORTOP(dvp, cnp); 93fab63cc4SDoug Rabson error = EMLINK; 94fab63cc4SDoug Rabson goto out1; 95fab63cc4SDoug Rabson } 96fab63cc4SDoug Rabson 97fab63cc4SDoug Rabson if (vp is immutable) { 98fab63cc4SDoug Rabson VOP_ABORTOP(dvp, cnp); 99fab63cc4SDoug Rabson error = EPERM; 100fab63cc4SDoug Rabson goto out1; 101fab63cc4SDoug Rabson } 102fab63cc4SDoug Rabson 103fab63cc4SDoug Rabson /* 104fab63cc4SDoug Rabson * Increment link count of vp and write back the on-disc version of it. 105fab63cc4SDoug Rabson */ 106fab63cc4SDoug Rabson ...; 107fab63cc4SDoug Rabson 108fab63cc4SDoug Rabson if (!error) { 109fab63cc4SDoug Rabson /* 110fab63cc4SDoug Rabson * Add the new name to the directory. 111fab63cc4SDoug Rabson */ 112fab63cc4SDoug Rabson ...; 113fab63cc4SDoug Rabson } 114fab63cc4SDoug Rabson 115fab63cc4SDoug Rabson free(cnp->cn_pnbuf, M_NAMEI); 116fab63cc4SDoug Rabsonout1: 117fab63cc4SDoug Rabson if (vp != dvp) 118fab63cc4SDoug Rabson VOP_UNLOCK(vp); 119fab63cc4SDoug Rabsonout2: 120fab63cc4SDoug Rabson 121fab63cc4SDoug Rabson return error; 122fab63cc4SDoug Rabson} 123fab63cc4SDoug Rabson.Ed 124fab63cc4SDoug Rabson.Sh ERRORS 125eaa8b244SMike Pritchard.Bl -tag -width Er 126fab63cc4SDoug Rabson.It Bq Er EPERM 127fab63cc4SDoug Rabsonthe file is immutable 128fab63cc4SDoug Rabson.El 129fab63cc4SDoug Rabson.Sh SEE ALSO 13037af2883SMatthew Dillon.Xr vnode 9 , 13137af2883SMatthew Dillon.Xr vn_lock 9 132fab63cc4SDoug Rabson.Sh AUTHORS 13337af2883SMatthew DillonThis man page was originally written by 134aaf1f16eSPhilippe Charnier.An Doug Rabson . 135