xref: /freebsd/share/man/man9/VOP_LOOKUP.9 (revision 97549c34ecaf74580941fdc9c5bd1050e4b1f6ce)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $FreeBSD$
30.\"
31.Dd November 24, 1997
32.Dt VOP_LOOKUP 9
33.Os
34.Sh NAME
35.Nm VOP_LOOKUP
36.Nd lookup a component of a pathname
37.Sh SYNOPSIS
38.In sys/param.h
39.In sys/vnode.h
40.In sys/namei.h
41.Ft int
42.Fn VOP_LOOKUP "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp"
43.Sh DESCRIPTION
44This entry point looks up a single pathname component in a given directory.
45.Pp
46Its arguments are:
47.Bl -tag -width vpp
48.It Fa dvp
49The locked vnode of the directory to search.
50.It Fa vpp
51The address of a variable where the resulting locked vnode should be stored.
52.It Fa cnp
53The pathname component to be searched for.
54.El
55.Pp
56.Fa Cnp
57is a pointer to a componentname structure defined as follows:
58.Bd -literal
59struct componentname {
60	/*
61	 * Arguments to lookup.
62	 */
63	u_long	cn_nameiop;	/* namei operation */
64	u_long	cn_flags;	/* flags to namei */
65	struct	thread *cn_thread;	/* thread requesting lookup */
66	struct	ucred *cn_cred;	/* credentials */
67	/*
68	 * Shared between lookup and commit routines.
69	 */
70	char	*cn_pnbuf;	/* pathname buffer */
71	char	*cn_nameptr;	/* pointer to looked up name */
72	long	cn_namelen;	/* length of looked up component */
73	u_long	cn_hash;	/* hash value of looked up name */
74	long	cn_consume;	/* chars to consume in lookup() */
75};
76.Ed
77.Pp
78Convert a component of a pathname into a pointer to a locked vnode.
79This is a very central and rather complicated routine.
80If the file system is not maintained in a strict tree hierarchy,
81this can result in a deadlock situation.
82.Pp
83The
84.Fa cnp->cn_nameiop
85argument is
86.Dv LOOKUP ,
87.Dv CREATE ,
88.Dv RENAME ,
89or
90.Dv DELETE
91depending on the intended use of the object.
92When
93.Dv CREATE ,
94.Dv RENAME ,
95or
96.Dv DELETE
97is specified, information usable in
98creating, renaming, or deleting a directory entry may be calculated.
99.Pp
100Overall outline of VOP_LOOKUP:
101.Bd -ragged -offset indent
102Check accessibility of directory.
103Look for name in cache, if found, then return name.
104Search for name in directory, goto to found or notfound as appropriate.
105.Ed
106.Pp
107notfound:
108.Bd -ragged -offset indent
109If creating or renaming and at end of pathname,
110return
111.Er EJUSTRETURN ,
112leaving info on available slots else return
113.Er ENOENT .
114.Ed
115.Pp
116found:
117.Bd -ragged -offset indent
118If at end of path and deleting, return information to allow delete.
119If at end of path and renaming, lock target
120inode and return info to allow rename.
121If not at end, add name to cache; if at end and neither creating
122nor deleting, add name to cache.
123.Ed
124.Sh LOCKS
125The directory,
126.Fa dvp
127should be locked on entry.
128If an error (note: the return value
129.Er EJUSTRETURN
130is not considered an error)
131is detected, it will be returned locked.
132Otherwise, it will be unlocked unless both
133.Dv LOCKPARENT
134and
135.Dv ISLASTCN
136are specified in
137.Fa cnp->cn_flags .
138If an entry is found in the directory, it will be returned locked.
139.Sh RETURN VALUES
140Zero is returned with
141.Fa *vpp
142set to the locked vnode of the file if the component is found.
143If the component being searched for is ".", then the vnode just has
144an extra reference added to it with
145.Xr vref 9 .
146The caller must take care to release the locks appropriately in this
147case.
148.Pp
149If the component is not found and the operation is
150.Dv CREATE
151or
152.Dv RENAME ,
153the flag
154.Dv ISLASTCN
155is specified and the operation would succeed, the special return value
156.Er EJUSTRETURN
157is returned.
158Otherwise, an appropriate error code is returned.
159.Sh ERRORS
160.Bl -tag -width Er
161.It Bq Er ENOTDIR
162The vnode
163.Fa dvp
164does not represent a directory.
165.It Bq Er ENOENT
166The component
167.Fa dvp
168was not found in this directory.
169.It Bq Er EACCES
170Access for the specified operation is denied.
171.It Bq Er EJUSTRETURN
172A
173.Dv CREATE
174or
175.Dv RENAME
176operation would be successful.
177.El
178.Sh SEE ALSO
179.Xr vnode 9 ,
180.Xr VOP_ACCESS 9 ,
181.Xr VOP_CREATE 9 ,
182.Xr VOP_MKDIR 9 ,
183.Xr VOP_MKNOD 9 ,
184.Xr VOP_RENAME 9 ,
185.Xr VOP_SYMLINK 9
186.Sh HISTORY
187The function
188.Nm
189appeared in
190.Bx 4.3 .
191.Sh AUTHORS
192This manual page was written by
193.An Doug Rabson ,
194with some text from comments in
195.Pa ufs_lookup.c .
196