xref: /freebsd/lib/libsys/mknod.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993
2*8269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
11*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
13*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
14*8269e767SBrooks Davis.\"    without specific prior written permission.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8269e767SBrooks Davis.\" SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd March 30, 2020
29*8269e767SBrooks Davis.Dt MKNOD 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm mknod ,
33*8269e767SBrooks Davis.Nm mknodat
34*8269e767SBrooks Davis.Nd make a special file node
35*8269e767SBrooks Davis.Sh LIBRARY
36*8269e767SBrooks Davis.Lb libc
37*8269e767SBrooks Davis.Sh SYNOPSIS
38*8269e767SBrooks Davis.In sys/stat.h
39*8269e767SBrooks Davis.Ft int
40*8269e767SBrooks Davis.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
41*8269e767SBrooks Davis.Ft int
42*8269e767SBrooks Davis.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev"
43*8269e767SBrooks Davis.Sh DESCRIPTION
44*8269e767SBrooks DavisThe file system node
45*8269e767SBrooks Davis.Fa path
46*8269e767SBrooks Davisis created with the file type and access permissions specified in
47*8269e767SBrooks Davis.Fa mode .
48*8269e767SBrooks DavisThe access permissions are modified by the process's umask value.
49*8269e767SBrooks Davis.Pp
50*8269e767SBrooks DavisIf
51*8269e767SBrooks Davis.Fa mode
52*8269e767SBrooks Davisindicates a block or character special file,
53*8269e767SBrooks Davis.Fa dev
54*8269e767SBrooks Davisis a configuration dependent specification denoting a particular device
55*8269e767SBrooks Davison the system.
56*8269e767SBrooks DavisOtherwise,
57*8269e767SBrooks Davis.Fa dev
58*8269e767SBrooks Davisis ignored.
59*8269e767SBrooks Davis.Pp
60*8269e767SBrooks DavisThe
61*8269e767SBrooks Davis.Fn mknod
62*8269e767SBrooks Davissystem call
63*8269e767SBrooks Davisrequires super-user privileges.
64*8269e767SBrooks Davis.Pp
65*8269e767SBrooks DavisThe
66*8269e767SBrooks Davis.Fn mknodat
67*8269e767SBrooks Davissystem call is equivalent to
68*8269e767SBrooks Davis.Fn mknod
69*8269e767SBrooks Davisexcept in the case where
70*8269e767SBrooks Davis.Fa path
71*8269e767SBrooks Davisspecifies a relative path.
72*8269e767SBrooks DavisIn this case the newly created device node is created relative to the
73*8269e767SBrooks Davisdirectory associated with the file descriptor
74*8269e767SBrooks Davis.Fa fd
75*8269e767SBrooks Davisinstead of the current working directory.
76*8269e767SBrooks DavisIf
77*8269e767SBrooks Davis.Fn mknodat
78*8269e767SBrooks Davisis passed the special value
79*8269e767SBrooks Davis.Dv AT_FDCWD
80*8269e767SBrooks Davisin the
81*8269e767SBrooks Davis.Fa fd
82*8269e767SBrooks Davisparameter, the current working directory is used and the behavior is
83*8269e767SBrooks Davisidentical to a call to
84*8269e767SBrooks Davis.Fn mknod .
85*8269e767SBrooks Davis.Sh RETURN VALUES
86*8269e767SBrooks Davis.Rv -std mknod
87*8269e767SBrooks Davis.Sh ERRORS
88*8269e767SBrooks DavisThe
89*8269e767SBrooks Davis.Fn mknod
90*8269e767SBrooks Davissystem call
91*8269e767SBrooks Daviswill fail and the file will be not created if:
92*8269e767SBrooks Davis.Bl -tag -width Er
93*8269e767SBrooks Davis.It Bq Er ENOTDIR
94*8269e767SBrooks DavisA component of the path prefix is not a directory.
95*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
96*8269e767SBrooks DavisA component of a pathname exceeded 255 characters,
97*8269e767SBrooks Davisor an entire path name exceeded 1023 characters.
98*8269e767SBrooks Davis.It Bq Er ENOENT
99*8269e767SBrooks DavisA component of the path prefix does not exist.
100*8269e767SBrooks Davis.It Bq Er EACCES
101*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix.
102*8269e767SBrooks Davis.It Bq Er ELOOP
103*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname.
104*8269e767SBrooks Davis.It Bq Er EPERM
105*8269e767SBrooks DavisThe process's effective user ID is not super-user.
106*8269e767SBrooks Davis.It Bq Er EIO
107*8269e767SBrooks DavisAn I/O error occurred while making the directory entry or allocating the inode.
108*8269e767SBrooks Davis.It Bq Er EINTEGRITY
109*8269e767SBrooks DavisCorrupted data was detected while reading from the file system.
110*8269e767SBrooks Davis.It Bq Er ENOSPC
111*8269e767SBrooks DavisThe directory in which the entry for the new node is being placed
112*8269e767SBrooks Daviscannot be extended because there is no space left on the file
113*8269e767SBrooks Davissystem containing the directory.
114*8269e767SBrooks Davis.It Bq Er ENOSPC
115*8269e767SBrooks DavisThere are no free inodes on the file system on which the
116*8269e767SBrooks Davisnode is being created.
117*8269e767SBrooks Davis.It Bq Er EDQUOT
118*8269e767SBrooks DavisThe directory in which the entry for the new node
119*8269e767SBrooks Davisis being placed cannot be extended because the
120*8269e767SBrooks Davisuser's quota of disk blocks on the file system
121*8269e767SBrooks Daviscontaining the directory has been exhausted.
122*8269e767SBrooks Davis.It Bq Er EDQUOT
123*8269e767SBrooks DavisThe user's quota of inodes on the file system on
124*8269e767SBrooks Daviswhich the node is being created has been exhausted.
125*8269e767SBrooks Davis.It Bq Er EROFS
126*8269e767SBrooks DavisThe named file resides on a read-only file system.
127*8269e767SBrooks Davis.It Bq Er EEXIST
128*8269e767SBrooks DavisThe named file exists.
129*8269e767SBrooks Davis.It Bq Er EFAULT
130*8269e767SBrooks DavisThe
131*8269e767SBrooks Davis.Fa path
132*8269e767SBrooks Davisargument
133*8269e767SBrooks Davispoints outside the process's allocated address space.
134*8269e767SBrooks Davis.It Bq Er EINVAL
135*8269e767SBrooks DavisCreating anything else than a block or character special
136*8269e767SBrooks Davisfile (or a
137*8269e767SBrooks Davis.Em whiteout )
138*8269e767SBrooks Davisis not supported.
139*8269e767SBrooks Davis.El
140*8269e767SBrooks Davis.Pp
141*8269e767SBrooks DavisIn addition to the errors returned by the
142*8269e767SBrooks Davis.Fn mknod ,
143*8269e767SBrooks Davisthe
144*8269e767SBrooks Davis.Fn mknodat
145*8269e767SBrooks Davismay fail if:
146*8269e767SBrooks Davis.Bl -tag -width Er
147*8269e767SBrooks Davis.It Bq Er EBADF
148*8269e767SBrooks DavisThe
149*8269e767SBrooks Davis.Fa path
150*8269e767SBrooks Davisargument does not specify an absolute path and the
151*8269e767SBrooks Davis.Fa fd
152*8269e767SBrooks Davisargument is neither
153*8269e767SBrooks Davis.Dv AT_FDCWD
154*8269e767SBrooks Davisnor a valid file descriptor open for searching.
155*8269e767SBrooks Davis.It Bq Er ENOTDIR
156*8269e767SBrooks DavisThe
157*8269e767SBrooks Davis.Fa path
158*8269e767SBrooks Davisargument is not an absolute path and
159*8269e767SBrooks Davis.Fa fd
160*8269e767SBrooks Davisis neither
161*8269e767SBrooks Davis.Dv AT_FDCWD
162*8269e767SBrooks Davisnor a file descriptor associated with a directory.
163*8269e767SBrooks Davis.El
164*8269e767SBrooks Davis.Sh SEE ALSO
165*8269e767SBrooks Davis.Xr chmod 2 ,
166*8269e767SBrooks Davis.Xr mkfifo 2 ,
167*8269e767SBrooks Davis.Xr stat 2 ,
168*8269e767SBrooks Davis.Xr umask 2
169*8269e767SBrooks Davis.Sh STANDARDS
170*8269e767SBrooks DavisThe
171*8269e767SBrooks Davis.Fn mknodat
172*8269e767SBrooks Davissystem call follows The Open Group Extended API Set 2 specification.
173*8269e767SBrooks Davis.Sh HISTORY
174*8269e767SBrooks DavisThe
175*8269e767SBrooks Davis.Fn mknod
176*8269e767SBrooks Davisfunction appeared in
177*8269e767SBrooks Davis.At v4 .
178*8269e767SBrooks DavisThe
179*8269e767SBrooks Davis.Fn mknodat
180*8269e767SBrooks Davissystem call appeared in
181*8269e767SBrooks Davis.Fx 8.0 .
182