xref: /freebsd/share/man/man9/VOP_LOOKUP.9 (revision e9dcd83155b39327497e7a2577d8990074144ff3)
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 August 8, 2018
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.
54It is a pointer to a componentname structure defined as follows:
55.Bd -literal
56struct componentname {
57	/*
58	 * Arguments to lookup.
59	 */
60	u_long	cn_nameiop;	/* namei operation */
61	u_long	cn_flags;	/* flags to namei */
62	struct	thread *cn_thread;	/* thread requesting lookup */
63	struct	ucred *cn_cred;	/* credentials */
64	int     cn_lkflags;     /* Lock flags LK_EXCLUSIVE or LK_SHARED */
65	/*
66	 * Shared between lookup and commit routines.
67	 */
68	char	*cn_pnbuf;	/* pathname buffer */
69	char	*cn_nameptr;	/* pointer to looked up name */
70	long	cn_namelen;	/* length of looked up component */
71};
72.Ed
73.Pp
74Convert a component of a pathname into a pointer to a locked vnode.
75This is a very central and rather complicated routine.
76If the file system is not maintained in a strict tree hierarchy,
77this can result in a deadlock situation.
78.Pp
79The
80.Fa cnp->cn_nameiop
81argument is
82.Dv LOOKUP ,
83.Dv CREATE ,
84.Dv RENAME ,
85or
86.Dv DELETE
87depending on the intended use of the object.
88When
89.Dv CREATE ,
90.Dv RENAME ,
91or
92.Dv DELETE
93is specified, information usable in
94creating, renaming, or deleting a directory entry may be calculated.
95.Pp
96Overall outline of VOP_LOOKUP:
97.Bd -ragged -offset indent
98Check accessibility of directory.
99Look for name in cache, if found, then return name.
100Search for name in directory, goto to found or notfound as appropriate.
101.Ed
102.Pp
103notfound:
104.Bd -ragged -offset indent
105If creating or renaming and at end of pathname,
106return
107.Er EJUSTRETURN ,
108leaving info on available slots else return
109.Er ENOENT .
110.Ed
111.Pp
112found:
113.Bd -ragged -offset indent
114If at end of path and deleting, return information to allow delete.
115If at end of path and renaming, lock target
116inode and return info to allow rename.
117If not at end, add name to cache; if at end and neither creating
118nor deleting, add name to cache.
119.Ed
120.Sh LOCKS
121The directory
122.Fa dvp
123should be locked on entry and exit, regardless of error condition.
124If an entry is found in the directory, it will be returned locked.
125.Sh RETURN VALUES
126Zero is returned with
127.Fa *vpp
128set to the locked vnode of the file if the component is found.
129If the component being searched for is ".", then the vnode just has
130an extra reference added to it with
131.Xr vref 9 .
132The caller must take care to release the locks appropriately in this
133case.
134.Pp
135If the component is not found and the operation is
136.Dv CREATE
137or
138.Dv RENAME ,
139the flag
140.Dv ISLASTCN
141is specified and the operation would succeed, the special return value
142.Er EJUSTRETURN
143is returned.
144Otherwise, an appropriate error code is returned.
145.Sh ERRORS
146.Bl -tag -width Er
147.It Bq Er ENOTDIR
148The vnode
149.Fa dvp
150does not represent a directory.
151.It Bq Er ENOENT
152The component
153.Fa dvp
154was not found in this directory.
155.It Bq Er EACCES
156Access for the specified operation is denied.
157.It Bq Er EJUSTRETURN
158A
159.Dv CREATE
160or
161.Dv RENAME
162operation would be successful.
163.El
164.Sh SEE ALSO
165.Xr vnode 9 ,
166.Xr VOP_ACCESS 9 ,
167.Xr VOP_CREATE 9 ,
168.Xr VOP_MKDIR 9 ,
169.Xr VOP_MKNOD 9 ,
170.Xr VOP_RENAME 9 ,
171.Xr VOP_SYMLINK 9
172.Sh HISTORY
173The function
174.Nm
175appeared in
176.Bx 4.3 .
177.Sh AUTHORS
178This manual page was written by
179.An Doug Rabson ,
180with some text from comments in
181.Pa ufs_lookup.c .
182