Fix comments:
[dragonfly.git] / share / man / man9 / VOP_CREATE.9
1 .\" Copyright (c) 1996 Doug Rabson
2 .\"
3 .\" All rights reserved.
4 .\"
5 .\" This program is free software.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD: src/share/man/man9/VOP_CREATE.9,v 1.9.2.1 2001/12/17 11:30:18 ru Exp $
28 .\" $DragonFly: src/share/man/man9/VOP_CREATE.9,v 1.5 2006/02/17 19:37:10 swildner Exp $
29 .\"
30 .Dd July 24, 1996
31 .Os
32 .Dt VOP_CREATE 9
33 .Sh NAME
34 .Nm VOP_CREATE ,
35 .Nm VOP_MKNOD ,
36 .Nm VOP_MKDIR ,
37 .Nm VOP_SYMLINK
38 .Nd create a file, socket, fifo, device, directory or symlink
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/vnode.h
42 .In sys/namei.h
43 .Ft int
44 .Fn VOP_CREATE "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
45 .Ft int
46 .Fn VOP_MKNOD "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
47 .Ft int
48 .Fn VOP_MKDIR "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap"
49 .Ft int
50 .Fn VOP_SYMLINK "struct vnode *dvp" "struct vnode **vpp" "struct componentname *cnp" "struct vattr *vap" "char *target"
51 .Sh DESCRIPTION
52 These entry points create a new file, socket, fifo, device, directory or symlink
53 in a given directory.
54 .Pp
55 The arguments are:
56 .Bl -tag -width target
57 .It Fa dvp
58 the locked vnode of the directory
59 .It Fa vpp
60 the address of a variable where the resulting locked vnode should be stored
61 .It Fa cnp
62 the pathname component created
63 .It Fa vap
64 the attributes that the new object should be created with
65 .It Fa target
66 the pathname of the target of the symlink
67 .El
68 .Pp
69 These entry points are called after
70 .Xr VOP_LOOKUP 9
71 when an object is being created.
72 Normally,
73 .Xr VOP_LOOKUP 9
74 will have set the
75 .Dv SAVENAME
76 flag in
77 .Fa cnp->cn_flags
78 to keep the memory pointed to by
79 .Fa cnp->cn_pnbuf
80 valid.
81 If an error is detected when creating the file,
82 then this memory will be freed.
83 If the file is created successfully, then it will be freed unless the
84 .Dv SAVESTART
85 flag is specified in
86 .Fa cnp .
87 .Sh LOCKS
88 The directory,
89 .Fa dvp
90 will be locked on entry and must remain locked on return.
91 If the call is successful, the new object will be returned locked.
92 .Sh RETURN VALUES
93 If successful, the vnode for the new object is placed in
94 .Fa *vpp
95 and zero is returned.  Otherwise, an appropriate error is returned.
96 .Sh PSEUDOCODE
97 .Bd -literal
98 int
99 vop_create(struct vnode *dvp,
100            struct vnode **vpp,
101            struct componentname *cnp
102            struct vattr *vap)
103 {
104     int mode = MAKEIMODE(vap->va_type, vap->va_mode);
105     struct vnode *vp;
106     int error;
107
108     *vpp = NULL;
109     if ((mode & IFMT) == 0)
110         mode |= IFREG;
111
112     error = SOMEFS_VALLOC(dvp, mode, cnp->cn_cred, &vp);
113     if (error) {
114         free(cnp->cn_pnbuf, M_NAMEI);
115         vput(dvp);
116         return error;
117     }
118
119     /*
120      * Update the permissions for the new vnode, including
121      * copying the group from the directory.
122      */
123     ...;
124
125 #ifdef QUOTA
126     /*
127      * Possibly check quota information.
128      */
129     ...;
130 #endif
131
132     /*
133      * Enter new vnode in directory, taking care that the vnode
134      * hits the disk before the directory contents are changed.
135      */
136     error = ...;
137
138     if (error)
139         goto bad;
140
141     if ((cnp->cn_flags & SAVESTART) == 0)
142         free(cnp->cn_pnbuf, M_NAMEI);
143     vput(dvp);
144     *vpp = vp;
145
146     return 0;
147
148 bad:
149     /*
150      * Write error occurred trying to update the inode
151      * or the directory so must deallocate the inode.
152      */
153     free(cnp->cn_pnbuf, M_NAMEI);
154     vput(vp);
155
156     /*
157      * Deallocate filesystem resources for vp.
158      */
159     ...;
160
161     vput(dvp);
162
163     return error;
164 }
165 .Ed
166 .Sh ERRORS
167 .Bl -tag -width Er
168 .It Bq Er ENOSPC
169 The filesystem is full.
170 .It Bq Er EDQUOT
171 Quota exceeded.
172 .El
173 .Sh SEE ALSO
174 .Xr vnode 9 ,
175 .Xr VOP_LOOKUP 9
176 .Sh HISTORY
177 The function
178 .Nm
179 appeared in
180 .Bx 4.3 .
181 .Sh AUTHORS
182 This man page was written by
183 .An Doug Rabson .