xref: /freebsd/share/man/man9/VOP_CREATE.9 (revision 6b3455a7665208c366849f0b2b3bc916fb97516e)
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.In sys/param.h
42.In sys/vnode.h
43.In 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
53These entry points create a new file, socket, fifo, device, directory or symlink
54in a given directory.
55.Pp
56The arguments are:
57.Bl -tag -width target
58.It Fa dvp
59the locked vnode of the directory
60.It Fa vpp
61the address of a variable where the resulting locked vnode should be stored
62.It Fa cnp
63the pathname component created
64.It Fa vap
65the attributes that the new object should be created with
66.It Fa target
67the pathname of the target of the symlink
68.El
69.Pp
70These entry points are called after
71.Xr VOP_LOOKUP 9
72when an object is being created.
73.Sh LOCKS
74The directory,
75.Fa dvp
76will be locked on entry and must remain locked on return.
77If the call is successful, the new object will be returned locked.
78.Sh RETURN VALUES
79If successful, the vnode for the new object is placed in
80.Fa *vpp
81and zero is returned.
82Otherwise, an appropriate error is returned.
83.Sh PSEUDOCODE
84.Bd -literal
85int
86vop_create(struct vnode *dvp,
87	   struct vnode **vpp,
88	   struct componentname *cnp
89	   struct vattr *vap)
90{
91    int mode = MAKEIMODE(vap->va_type, vap->va_mode);
92    struct vnode *vp;
93    int error;
94
95    *vpp = NULL;
96    if ((mode & IFMT) == 0)
97	mode |= IFREG;
98
99    error = SOMEFS_VALLOC(dvp, mode, cnp->cn_cred, &vp);
100    if (error)
101	return error;
102
103    /*
104     * Update the permissions for the new vnode, including
105     * copying the group from the directory.
106     */
107    ...;
108
109#ifdef QUOTA
110    /*
111     * Possibly check quota information.
112     */
113    ...;
114#endif
115
116    /*
117     * Enter new vnode in directory, taking care that the vnode
118     * hits the disk before the directory contents are changed.
119     */
120    error = ...;
121
122    if (error)
123	goto bad;
124
125    *vpp = vp;
126
127    return 0;
128
129bad:
130    /*
131     * Write error occurred trying to update the inode
132     * or the directory so must deallocate the inode.
133     */
134    vput(vp);
135
136    /*
137     * Deallocate file system resources for vp.
138     */
139    ...;
140
141    return error;
142}
143.Ed
144.Sh ERRORS
145.Bl -tag -width Er
146.It Bq Er ENOSPC
147The file system is full.
148.It Bq Er EDQUOT
149The user's file system space or inode quota would be exceeded.
150.El
151.Sh SEE ALSO
152.Xr VOP_LOOKUP 9
153.Sh HISTORY
154The function
155.Nm
156appeared in
157.Bx 4.3 .
158.Sh SEE ALSO
159.Xr vnode 9
160.Sh AUTHORS
161This man page was written by
162.An Doug Rabson .
163