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.\" 29880cdb88SAlan Somers.Dd August 8, 2018 30fab63cc4SDoug Rabson.Dt VOP_LOOKUP 9 31aa12cea2SUlrich Spörlein.Os 32fab63cc4SDoug Rabson.Sh NAME 33fab63cc4SDoug Rabson.Nm VOP_LOOKUP 34fab63cc4SDoug Rabson.Nd lookup a component of a pathname 35fab63cc4SDoug Rabson.Sh SYNOPSIS 3632eef9aeSRuslan Ermilov.In sys/param.h 3732eef9aeSRuslan Ermilov.In sys/vnode.h 3832eef9aeSRuslan Ermilov.In sys/namei.h 39fab63cc4SDoug Rabson.Ft int 40fab63cc4SDoug Rabson.Fn VOP_LOOKUP "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" 41fab63cc4SDoug Rabson.Sh DESCRIPTION 423fd51560SBen SmithurstThis entry point looks up a single pathname component in a given directory. 43fab63cc4SDoug Rabson.Pp 44fab63cc4SDoug RabsonIts arguments are: 45fab63cc4SDoug Rabson.Bl -tag -width vpp 460640e9e0SHiten Pandya.It Fa dvp 470a57ea7dSRuslan ErmilovThe locked vnode of the directory to search. 480640e9e0SHiten Pandya.It Fa vpp 490a57ea7dSRuslan ErmilovThe address of a variable where the resulting locked vnode should be stored. 500640e9e0SHiten Pandya.It Fa cnp 510a57ea7dSRuslan ErmilovThe pathname component to be searched for. 52880cdb88SAlan SomersIt is a pointer to a componentname structure defined as follows: 53fab63cc4SDoug Rabson.Bd -literal 54fab63cc4SDoug Rabsonstruct componentname { 55fab63cc4SDoug Rabson /* 56fab63cc4SDoug Rabson * Arguments to lookup. 57fab63cc4SDoug Rabson */ 58fab63cc4SDoug Rabson u_long cn_nameiop; /* namei operation */ 59fab63cc4SDoug Rabson u_long cn_flags; /* flags to namei */ 60f6bd5d1eSAlfred Perlstein struct thread *cn_thread; /* thread requesting lookup */ 61fab63cc4SDoug Rabson struct ucred *cn_cred; /* credentials */ 62880cdb88SAlan Somers int cn_lkflags; /* Lock flags LK_EXCLUSIVE or LK_SHARED */ 63fab63cc4SDoug Rabson /* 64fab63cc4SDoug Rabson * Shared between lookup and commit routines. 65fab63cc4SDoug Rabson */ 66fab63cc4SDoug Rabson char *cn_pnbuf; /* pathname buffer */ 67fab63cc4SDoug Rabson char *cn_nameptr; /* pointer to looked up name */ 68fab63cc4SDoug Rabson long cn_namelen; /* length of looked up component */ 69fab63cc4SDoug Rabson}; 70fab63cc4SDoug Rabson.Ed 71*16ee5cd1SChristian Brueffer.El 72fab63cc4SDoug Rabson.Pp 73fab63cc4SDoug RabsonConvert a component of a pathname into a pointer to a locked vnode. 74fab63cc4SDoug RabsonThis is a very central and rather complicated routine. 75fab63cc4SDoug RabsonIf the file system is not maintained in a strict tree hierarchy, 76fab63cc4SDoug Rabsonthis can result in a deadlock situation. 77fab63cc4SDoug Rabson.Pp 78fab63cc4SDoug RabsonThe 79fab63cc4SDoug Rabson.Fa cnp->cn_nameiop 80fab63cc4SDoug Rabsonargument is 81fab63cc4SDoug Rabson.Dv LOOKUP , 82fab63cc4SDoug Rabson.Dv CREATE , 83fab63cc4SDoug Rabson.Dv RENAME , 84fab63cc4SDoug Rabsonor 85fab63cc4SDoug Rabson.Dv DELETE 86fab63cc4SDoug Rabsondepending on the intended use of the object. 87fab63cc4SDoug RabsonWhen 88fab63cc4SDoug Rabson.Dv CREATE , 89fab63cc4SDoug Rabson.Dv RENAME , 90fab63cc4SDoug Rabsonor 91fab63cc4SDoug Rabson.Dv DELETE 92fab63cc4SDoug Rabsonis specified, information usable in 93fab63cc4SDoug Rabsoncreating, renaming, or deleting a directory entry may be calculated. 94fab63cc4SDoug Rabson.Pp 95fab63cc4SDoug RabsonOverall outline of VOP_LOOKUP: 9646eea498SRuslan Ermilov.Bd -ragged -offset indent 97fab63cc4SDoug RabsonCheck accessibility of directory. 98fab63cc4SDoug RabsonLook for name in cache, if found, then return name. 99fab63cc4SDoug RabsonSearch for name in directory, goto to found or notfound as appropriate. 100fab63cc4SDoug Rabson.Ed 101fab63cc4SDoug Rabson.Pp 102fab63cc4SDoug Rabsonnotfound: 10346eea498SRuslan Ermilov.Bd -ragged -offset indent 104fab63cc4SDoug RabsonIf creating or renaming and at end of pathname, 105fab63cc4SDoug Rabsonreturn 106b92a189eSRuslan Ermilov.Er EJUSTRETURN , 107fab63cc4SDoug Rabsonleaving info on available slots else return 108b92a189eSRuslan Ermilov.Er ENOENT . 109fab63cc4SDoug Rabson.Ed 110fab63cc4SDoug Rabson.Pp 111fab63cc4SDoug Rabsonfound: 11246eea498SRuslan Ermilov.Bd -ragged -offset indent 113fab63cc4SDoug RabsonIf at end of path and deleting, return information to allow delete. 114fab63cc4SDoug RabsonIf at end of path and renaming, lock target 115fab63cc4SDoug Rabsoninode and return info to allow rename. 116fab63cc4SDoug RabsonIf not at end, add name to cache; if at end and neither creating 117fab63cc4SDoug Rabsonnor deleting, add name to cache. 118fab63cc4SDoug Rabson.Ed 119fab63cc4SDoug Rabson.Sh LOCKS 12027a077f2SAlan SomersThe directory 121fab63cc4SDoug Rabson.Fa dvp 12227a077f2SAlan Somersshould be locked on entry and exit, regardless of error condition. 123fab63cc4SDoug RabsonIf an entry is found in the directory, it will be returned locked. 124fab63cc4SDoug Rabson.Sh RETURN VALUES 125fab63cc4SDoug RabsonZero is returned with 126fab63cc4SDoug Rabson.Fa *vpp 127fab63cc4SDoug Rabsonset to the locked vnode of the file if the component is found. 128fab63cc4SDoug RabsonIf the component being searched for is ".", then the vnode just has 129fab63cc4SDoug Rabsonan extra reference added to it with 130fab63cc4SDoug Rabson.Xr vref 9 . 131fab63cc4SDoug RabsonThe caller must take care to release the locks appropriately in this 132fab63cc4SDoug Rabsoncase. 133fab63cc4SDoug Rabson.Pp 134fab63cc4SDoug RabsonIf the component is not found and the operation is 135fab63cc4SDoug Rabson.Dv CREATE 136fab63cc4SDoug Rabsonor 137fab63cc4SDoug Rabson.Dv RENAME , 138fab63cc4SDoug Rabsonthe flag 139fab63cc4SDoug Rabson.Dv ISLASTCN 140fab63cc4SDoug Rabsonis specified and the operation would succeed, the special return value 141b92a189eSRuslan Ermilov.Er EJUSTRETURN 142fab63cc4SDoug Rabsonis returned. 143fab63cc4SDoug RabsonOtherwise, an appropriate error code is returned. 144fab63cc4SDoug Rabson.Sh ERRORS 145eaa8b244SMike Pritchard.Bl -tag -width Er 146fab63cc4SDoug Rabson.It Bq Er ENOTDIR 147fab63cc4SDoug RabsonThe vnode 148fab63cc4SDoug Rabson.Fa dvp 149fab63cc4SDoug Rabsondoes not represent a directory. 150fab63cc4SDoug Rabson.It Bq Er ENOENT 151fab63cc4SDoug RabsonThe component 152fab63cc4SDoug Rabson.Fa dvp 153fab63cc4SDoug Rabsonwas not found in this directory. 15422301c4bSBruce Evans.It Bq Er EACCES 155cc258457SDon LewisAccess for the specified operation is denied. 156fab63cc4SDoug Rabson.It Bq Er EJUSTRETURN 157cc258457SDon LewisA 158fab63cc4SDoug Rabson.Dv CREATE 159fab63cc4SDoug Rabsonor 160fab63cc4SDoug Rabson.Dv RENAME 161cc258457SDon Lewisoperation would be successful. 162fab63cc4SDoug Rabson.El 163fab63cc4SDoug Rabson.Sh SEE ALSO 16487968949SRuslan Ermilov.Xr vnode 9 , 165fab63cc4SDoug Rabson.Xr VOP_ACCESS 9 , 166fab63cc4SDoug Rabson.Xr VOP_CREATE 9 , 167fab63cc4SDoug Rabson.Xr VOP_MKDIR 9 , 168bceb8aedSWolfram Schneider.Xr VOP_MKNOD 9 , 169fab63cc4SDoug Rabson.Xr VOP_RENAME 9 , 170bceb8aedSWolfram Schneider.Xr VOP_SYMLINK 9 171fab63cc4SDoug Rabson.Sh HISTORY 172fab63cc4SDoug RabsonThe function 173fab63cc4SDoug Rabson.Nm 174eaa8b244SMike Pritchardappeared in 175eaa8b244SMike Pritchard.Bx 4.3 . 176fab63cc4SDoug Rabson.Sh AUTHORS 177571dba6eSHiten PandyaThis manual page was written by 178aaf1f16eSPhilippe Charnier.An Doug Rabson , 179aaf1f16eSPhilippe Charnierwith some text from comments in 180aaf1f16eSPhilippe Charnier.Pa ufs_lookup.c . 181