1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt
3 .\" and Copyright (C) 1993,1994 Ian Jackson
4 .\" and Copyright (C) 2006, 2014, Michael Kerrisk
6 .\" SPDX-License-Identifier: GPL-1.0-or-later
8 .\" Modified 1996-08-18 by urs
9 .\" Modified 2003-04-23 by Michael Kerrisk
10 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
12 .TH MKNOD 2 2022-09-09 "Linux man-pages (unreleased)"
14 mknod, mknodat \- create a special or ordinary file
17 .RI ( libc ", " \-lc )
20 .B #include <sys/stat.h>
22 .BI "int mknod(const char *" pathname ", mode_t " mode ", dev_t " dev );
24 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
25 .B #include <sys/stat.h>
27 .BI "int mknodat(int " dirfd ", const char *" pathname ", mode_t " mode \
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
39 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
40 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
41 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
46 creates a filesystem node (file, device special file, or
49 with attributes specified by
56 argument specifies both the file mode to use and the type of node
58 It should be a combination (using bitwise OR) of one of the file types
59 listed below and zero or more of the file mode bits listed in
62 The file mode is modified by the process's
64 in the usual way: in the absence of a default ACL, the permissions of the
66 .RI ( mode " & \(ti" umask ).
68 The file type must be one of
75 .\" (S_IFSOCK since Linux 1.2.4)
76 to specify a regular file (which will be created empty), character
77 special file, block special file, FIFO (named pipe), or UNIX domain socket,
79 (Zero file type is equivalent to type
88 specifies the major and minor numbers of the newly created device
91 may be useful to build the value for
93 otherwise it is ignored.
97 already exists, or is a symbolic link, this call fails with an
101 The newly created node will be owned by the effective user ID of the
103 If the directory containing the node has the set-group-ID
104 bit set, or if the filesystem is mounted with BSD group semantics, the
105 new node will inherit the group ownership from its parent directory;
106 otherwise it will be owned by the effective group ID of the process.
112 system call operates in exactly the same way as
114 except for the differences described here.
116 If the pathname given in
118 is relative, then it is interpreted relative to the directory
119 referred to by the file descriptor
121 (rather than relative to the current working directory of
122 the calling process, as is done by
124 for a relative pathname).
134 is interpreted relative to the current working
135 directory of the calling process (like
146 for an explanation of the need for
152 return zero on success.
153 On error, \-1 is returned and
155 is set to indicate the error.
159 The parent directory does not allow write permission to the process,
160 or one of the directories in the path prefix of
162 did not allow search permission.
164 .BR path_resolution (7).)
173 nor a valid file descriptor.
176 The user's quota of disk blocks or inodes on the filesystem has been
182 This includes the case where
184 is a symbolic link, dangling or not.
187 .IR pathname " points outside your accessible address space."
191 requested creation of something other than a regular file, device
192 special file, FIFO or socket.
195 Too many symbolic links were encountered in resolving
199 .IR pathname " was too long."
202 A directory component in
204 does not exist or is a dangling symbolic link.
207 Insufficient kernel memory was available.
210 The device containing
212 has no room for the new node.
215 A component used as a directory in
217 is not, in fact, a directory.
224 is a file descriptor referring to a file other than a directory.
228 requested creation of something other than a regular file,
229 FIFO (named pipe), or UNIX domain socket, and the caller
230 is not privileged (Linux: does not have the
233 .\" For UNIX domain sockets and regular files, EPERM is returned only in
234 .\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
235 .\" use mknod() to make these files.
236 also returned if the filesystem containing
238 does not support the type of node requested.
242 refers to a file on a read-only filesystem.
245 was added to Linux in kernel 2.6.16;
246 library support was added to glibc in version 2.4.
249 SVr4, 4.4BSD, POSIX.1-2001 (but see below), POSIX.1-2008.
250 .\" The Linux version differs from the SVr4 version in that it
251 .\" does not require root permission to create pipes, also in that no
252 .\" EMULTIHOP, ENOLINK, or EINTR error is documented.
257 POSIX.1-2001 says: "The only portable use of
259 is to create a FIFO-special file.
266 is not 0, the behavior of
269 However, nowadays one should never use
271 for this purpose; one should use
273 a function especially defined for this purpose.
277 cannot be used to create directories.
278 One should make directories with
280 .\" and one should make UNIX domain sockets with socket(2) and bind(2).
282 There are many infelicities in the protocol underlying NFS.
301 .BR path_resolution (7)