]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/VOP_CREATE.9
This commit was generated by cvs2svn to compensate for changes in r51415,
[FreeBSD/FreeBSD.git] / share / man / man9 / VOP_CREATE.9
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 July 24, 1996
32 .Os
33 .Dt VOP_CREATE 9
34 .Sh NAME
35 .Nm VOP_CREATE ,
36 .Nm VOP_MKNOD ,
37 .Nm VOP_MKDIR ,
38 .Nm VOP_SYMLINK
39 .Nd create a file, socket, fifo, device, directory or symlink
40 .Sh SYNOPSIS
41 .Fd #include <sys/param.h>
42 .Fd #include <sys/vnode.h>
43 .Fd #include <sys/namei.h>
44 .Ft int
45 .Fn VOP_CREATE "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
46 .Ft int
47 .Fn VOP_MKNOD "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
48 .Ft int
49 .Fn VOP_MKDIR "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
50 .Ft int
51 .Fn VOP_SYMLINK "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" "char *target"
52 .Sh DESCRIPTION
53 These entry points create a new file, socket, fifo, device, directory or symlink
54 in a given directory.
55 .Pp
56 The arguments are:
57 .Bl -tag -width target
58 .It Ar dvp
59 the locked vnode of the directory
60 .It Ar vpp
61 the address of a variable where the resulting locked vnode should be stored
62 .It Ar cnp
63 the pathname component created
64 .It Ar vap
65 the attributes that the new object should be created with
66 .It Ar target
67 the pathname of the target of the symlink
68 .El
69 .Pp
70 These entry points are called after
71 .Xr VOP_LOOKUP 9
72 when an object is being created.
73 Normally,
74 .Xr VOP_LOOKUP 9
75 will have set the
76 .Dv SAVENAME
77 flag in
78 .Fa cnp->cn_flags
79 to keep the memory pointed to by
80 .Fa cnp->cn_pnbuf
81 valid.
82 If an error is detected when creating the file,
83 then this memory will be freed.
84 If the file is created successfully, then it will be freed unless the
85 .Dv SAVESTART
86 flag is specified in
87 .Fa cnp .
88 .Sh LOCKS
89 The directory,
90 .Fa dvp
91 should be locked on entry and will be unlocked and released on exit.
92 If the call is successful, the new object will be returned locked,
93 unless the call is
94 .Xr VOP_MKNOD 9
95 or
96 .Xr VOP_SYMLINK 9
97 in which case the new object is not returned at all.
98 It is not clear why
99 .Xr VOP_MKNOD 9
100 and
101 .Xr VOP_SYMLINK 9
102 need a
103 .Fa *vpp
104 argument at all.
105 .Sh RETURN VALUES
106 If successful, the vnode for the new object is placed in
107 .Fa *vpp
108 and zero is returned.  Otherwise, an appropriate error is returned.
109 .Sh PSEUDOCODE
110 .Bd -literal
111 int
112 vop_create(struct vnode *dvp,
113            struct vnode **vpp,
114            struct componentname *cnp
115            struct vattr *vap)
116 {
117     int mode = MAKEIMODE(vap->va_type, vap->va_mode);
118     struct vnode *vp;
119     int error;
120
121     *vpp = NULL;
122     if ((mode & IFMT) == 0)
123         mode |= IFREG;
124
125     error = SOMEFS_VALLOC(dvp, mode, cnp->cn_cred, &vp);
126     if (error) {
127         free(cnp->cn_pnbuf, M_NAMEI);
128         vput(dvp);
129         return error;
130     }
131
132     /*
133      * Update the permissions for the new vnode, including
134      * copying the group from the directory.
135      */
136     ...;
137
138 #ifdef QUOTA
139     /*
140      * Possibly check quota information.
141      */
142     ...;
143 #endif
144
145     /*
146      * Enter new vnode in directory, taking care that the vnode
147      * hits the disk before the directory contents are changed.
148      */
149     error = ...;
150
151     if (error)
152         goto bad;
153
154     if ((cnp->cn_flags & SAVESTART) == 0)
155         free(cnp->cn_pnbuf, M_NAMEI);
156     vput(dvp);
157     *vpp = vp;
158
159     return 0;
160
161 bad:
162     /*
163      * Write error occurred trying to update the inode
164      * or the directory so must deallocate the inode.
165      */
166     free(cnp->cn_pnbuf, M_NAMEI);
167     vput(vp);
168
169     /*
170      * Deallocate filesystem resources for vp.
171      */
172     ...;
173
174     vput(dvp);
175
176     return error;
177 }
178 .Ed
179 .Sh ERRORS
180 .Bl -tag -width Er
181 .It Bq Er ENOSPC
182 The filesystem is full.
183 .It Bq Er EDQUOT
184 Quota exceeded.
185 .El
186 .Sh SEE ALSO
187 .Xr VOP_LOOKUP 9
188 .Sh HISTORY
189 The function
190 .Nm
191 appeared in
192 .Bx 4.3 .
193 .Sh SEE ALSO
194 .Xr vnode 9
195 .Sh AUTHORS
196 This man page was written by
197 .An Doug Rabson .