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