]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/mknod.2
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man2 / mknod.2
CommitLineData
fea681da 1.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
ac56b6a8 2.\" and Copyright (C) 1993 Michael Haardt
60e7d95b
MK
3.\" and Copyright (C) 1993,1994 Ian Jackson
4.\" and Copyright (C) 2006, 2014, Michael Kerrisk
2297bf0e 5.\"
fd0fc519 6.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
fea681da 7.\" You may distribute it under the terms of the GNU General
d9bfdb9c 8.\" Public License. It comes with NO WARRANTY.
fd0fc519 9.\" %%%LICENSE_END
fea681da
MK
10.\"
11.\" Modified 1996-08-18 by urs
12.\" Modified 2003-04-23 by Michael Kerrisk
c11b1abf 13.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 14.\"
4b8c67d9 15.TH MKNOD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
fea681da 16.SH NAME
60e7d95b 17mknod, mknodat \- create a special or ordinary file
fea681da
MK
18.SH SYNOPSIS
19.nf
20.B #include <sys/types.h>
21.B #include <sys/stat.h>
22.B #include <fcntl.h>
23.B #include <unistd.h>
68e4db0a 24.PP
fea681da 25.BI "int mknod(const char *" pathname ", mode_t " mode ", dev_t " dev );
f90f031e 26
60e7d95b
MK
27.BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
28.B #include <sys/stat.h>
68e4db0a 29.PP
60e7d95b
MK
30.BI "int mknodat(int " dirfd ", const char *" pathname ", mode_t " mode \
31", dev_t " dev );
fea681da 32.fi
68e4db0a 33.PP
cc4615cc
MK
34.in -4n
35Feature Test Macro Requirements for glibc (see
36.BR feature_test_macros (7)):
37.in
68e4db0a 38.PP
cc4615cc 39.BR mknod ():
ba8c5128
MK
40.ad l
41.RS 4
f8619b6a 42_XOPEN_SOURCE\ >=\ 500
cf7fa0a1 43.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
f8619b6a 44 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
2c767761 45 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
ba8c5128
MK
46.RE
47.ad
fea681da
MK
48.SH DESCRIPTION
49The system call
e511ffb6 50.BR mknod ()
ba96eb7d 51creates a filesystem node (file, device special file, or
fea681da
MK
52named pipe) named
53.IR pathname ,
54with attributes specified by
55.I mode
56and
57.IR dev .
efeece04 58.PP
fea681da
MK
59The
60.I mode
9fcca5a0 61argument specifies both the file mode to use and the type of node
fea681da
MK
62to be created.
63It should be a combination (using bitwise OR) of one of the file types
9fcca5a0 64listed below and zero or more of the file mode bits listed in
e6fc1596 65.BR inode (7).
efeece04 66.PP
9fcca5a0 67The file mode is modified by the process's
0daa9e92 68.I umask
a57c98a0 69in the usual way: in the absence of a default ACL, the permissions of the
5d817eb4
AG
70created node are
71.RI ( mode " & ~" umask ).
efeece04 72.PP
fea681da
MK
73The file type must be one of
74.BR S_IFREG ,
75.BR S_IFCHR ,
76.BR S_IFBLK ,
43ff9b28 77.BR S_IFIFO ,
fea681da 78or
0daa9e92 79.B S_IFSOCK
fea681da 80.\" (S_IFSOCK since Linux 1.2.4)
21035964 81to specify a regular file (which will be created empty), character
008f1ecc 82special file, block special file, FIFO (named pipe), or UNIX domain socket,
fea681da 83respectively.
682edefb
MK
84(Zero file type is equivalent to type
85.BR S_IFREG .)
efeece04 86.PP
fea681da 87If the file type is
90a04948
MK
88.B S_IFCHR
89or
df53e85b 90.BR S_IFBLK ,
fea681da
MK
91then
92.I dev
93specifies the major and minor numbers of the newly created device
6437f56b
MK
94special file
95.RB ( makedev (3)
96may be useful to build the value for
97.IR dev );
98otherwise it is ignored.
efeece04 99.PP
fea681da
MK
100If
101.I pathname
682edefb
MK
102already exists, or is a symbolic link, this call fails with an
103.B EEXIST
104error.
efeece04 105.PP
fea681da 106The newly created node will be owned by the effective user ID of the
c13182ef
MK
107process.
108If the directory containing the node has the set-group-ID
9ee4a2b6 109bit set, or if the filesystem is mounted with BSD group semantics, the
fea681da
MK
110new node will inherit the group ownership from its parent directory;
111otherwise it will be owned by the effective group ID of the process.
60e7d95b
MK
112.\"
113.\"
114.SS mknodat()
115The
116.BR mknodat ()
117system call operates in exactly the same way as
bf7bc8b8 118.BR mknod (),
60e7d95b 119except for the differences described here.
efeece04 120.PP
60e7d95b
MK
121If the pathname given in
122.I pathname
123is relative, then it is interpreted relative to the directory
124referred to by the file descriptor
125.I dirfd
126(rather than relative to the current working directory of
127the calling process, as is done by
bf7bc8b8 128.BR mknod ()
60e7d95b 129for a relative pathname).
efeece04 130.PP
60e7d95b
MK
131If
132.I pathname
133is relative and
134.I dirfd
135is the special value
136.BR AT_FDCWD ,
137then
138.I pathname
139is interpreted relative to the current working
140directory of the calling process (like
bf7bc8b8 141.BR mknod ()).
efeece04 142.PP
60e7d95b
MK
143If
144.I pathname
145is absolute, then
146.I dirfd
147is ignored.
148.PP
149See
150.BR openat (2)
151for an explanation of the need for
152.BR mknodat ().
47297adb 153.SH RETURN VALUE
e511ffb6 154.BR mknod ()
60e7d95b
MK
155and
156.BR mknodat ()
157return zero on success, or \-1 if an error occurred (in which case,
fea681da
MK
158.I errno
159is set appropriately).
160.SH ERRORS
161.TP
162.B EACCES
163The parent directory does not allow write permission to the process,
164or one of the directories in the path prefix of
0daa9e92 165.I pathname
fea681da
MK
166did not allow search permission.
167(See also
ad7cc990 168.BR path_resolution (7).)
fea681da 169.TP
a1f01685 170.B EDQUOT
9ee4a2b6 171The user's quota of disk blocks or inodes on the filesystem has been
a1f01685
MH
172exhausted.
173.TP
fea681da
MK
174.B EEXIST
175.I pathname
176already exists.
9d6299e8
MK
177This includes the case where
178.I pathname
179is a symbolic link, dangling or not.
fea681da
MK
180.TP
181.B EFAULT
182.IR pathname " points outside your accessible address space."
183.TP
184.B EINVAL
185.I mode
21035964 186requested creation of something other than a regular file, device
fea681da
MK
187special file, FIFO or socket.
188.TP
189.B ELOOP
190Too many symbolic links were encountered in resolving
191.IR pathname .
192.TP
193.B ENAMETOOLONG
194.IR pathname " was too long."
195.TP
196.B ENOENT
197A directory component in
198.I pathname
199does not exist or is a dangling symbolic link.
200.TP
201.B ENOMEM
202Insufficient kernel memory was available.
203.TP
204.B ENOSPC
205The device containing
206.I pathname
207has no room for the new node.
208.TP
209.B ENOTDIR
210A component used as a directory in
211.I pathname
212is not, in fact, a directory.
213.TP
214.B EPERM
215.I mode
216requested creation of something other than a regular file,
008f1ecc 217FIFO (named pipe), or UNIX domain socket, and the caller
fea681da
MK
218is not privileged (Linux: does not have the
219.B CAP_MKNOD
6e5a7309 220capability);
33a0ccb2 221.\" For UNIX domain sockets and regular files, EPERM is returned only in
6e5a7309
MK
222.\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
223.\" use mknod() to make these files.
9ee4a2b6 224also returned if the filesystem containing
fea681da
MK
225.I pathname
226does not support the type of node requested.
227.TP
228.B EROFS
229.I pathname
9ee4a2b6 230refers to a file on a read-only filesystem.
60e7d95b
MK
231.PP
232The following additional errors can occur for
233.BR mknodat ():
234.TP
235.B EBADF
236.I dirfd
237is not a valid file descriptor.
238.TP
239.B ENOTDIR
240.I pathname
241is relative and
242.I dirfd
243is a file descriptor referring to a file other than a directory.
244.SH VERSIONS
245.BR mknodat ()
246was added to Linux in kernel 2.6.16;
247library support was added to glibc in version 2.4.
47297adb 248.SH CONFORMING TO
60e7d95b 249.BR mknod ():
55854bb8 250SVr4, 4.4BSD, POSIX.1-2001 (but see below), POSIX.1-2008.
97c1eac8
MK
251.\" The Linux version differs from the SVr4 version in that it
252.\" does not require root permission to create pipes, also in that no
253.\" EMULTIHOP, ENOLINK, or EINTR error is documented.
efeece04 254.PP
60e7d95b
MK
255.BR mknodat ():
256POSIX.1-2008.
fea681da 257.SH NOTES
97c1eac8 258POSIX.1-2001 says: "The only portable use of
fea681da 259.BR mknod ()
c13182ef
MK
260is to create a FIFO-special file.
261If
fea681da 262.I mode
90a04948
MK
263is not
264.B S_IFIFO
265or
fea681da
MK
266.I dev
267is not 0, the behavior of
268.BR mknod ()
269is unspecified."
3920c8ca
MK
270However, nowadays one should never use
271.BR mknod ()
272for this purpose; one should use
273.BR mkfifo (3),
274a function especially defined for this purpose.
efeece04 275.PP
53eeabde
MK
276Under Linux,
277.BR mknod ()
278cannot be used to create directories.
fea681da 279One should make directories with
3920c8ca 280.BR mkdir (2).
008f1ecc 281.\" and one should make UNIX domain sockets with socket(2) and bind(2).
efeece04 282.PP
c13182ef
MK
283There are many infelicities in the protocol underlying NFS.
284Some of these affect
53eeabde
MK
285.BR mknod ()
286and
4956bbd3 287.BR mknodat ().
47297adb 288.SH SEE ALSO
5a224378 289.BR mknod (1),
a3bf8022
MK
290.BR chmod (2),
291.BR chown (2),
fea681da
MK
292.BR fcntl (2),
293.BR mkdir (2),
294.BR mount (2),
fea681da
MK
295.BR socket (2),
296.BR stat (2),
297.BR umask (2),
298.BR unlink (2),
6437f56b 299.BR makedev (3),
ad7cc990 300.BR mkfifo (3),
11af6067 301.BR acl (5),
ad7cc990 302.BR path_resolution (7)