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