1mknod(2)                      System Calls Manual                     mknod(2)
2
3
4

NAME

6       mknod, mknodat - create a special or ordinary file
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/stat.h>
13
14       int mknod(const char *pathname, mode_t mode, dev_t dev);
15
16       #include <fcntl.h>           /* Definition of AT_* constants */
17       #include <sys/stat.h>
18
19       int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
20
21   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23       mknod():
24           _XOPEN_SOURCE >= 500
25               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
26               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
27

DESCRIPTION

29       The system call mknod() creates a filesystem node (file, device special
30       file, or named pipe) named pathname, with attributes specified by  mode
31       and dev.
32
33       The  mode  argument specifies both the file mode to use and the type of
34       node to be created.  It should be a combination (using bitwise  OR)  of
35       one  of  the  file types listed below and zero or more of the file mode
36       bits listed in inode(7).
37
38       The file mode is modified by the process's umask in the usual  way:  in
39       the  absence  of a default ACL, the permissions of the created node are
40       (mode & ~umask).
41
42       The file type must be one of S_IFREG,  S_IFCHR,  S_IFBLK,  S_IFIFO,  or
43       S_IFSOCK to specify a regular file (which will be created empty), char‐
44       acter special file, block special file, FIFO (named pipe), or UNIX  do‐
45       main  socket,  respectively.   (Zero  file  type  is equivalent to type
46       S_IFREG.)
47
48       If the file type is S_IFCHR or S_IFBLK, then dev  specifies  the  major
49       and  minor numbers of the newly created device special file (makedev(3)
50       may be useful to build the value for dev); otherwise it is ignored.
51
52       If pathname already exists, or is a symbolic link, this call fails with
53       an EEXIST error.
54
55       The  newly  created  node will be owned by the effective user ID of the
56       process.  If the directory containing the node has the set-group-ID bit
57       set,  or if the filesystem is mounted with BSD group semantics, the new
58       node will inherit the group ownership from its parent directory; other‐
59       wise it will be owned by the effective group ID of the process.
60
61   mknodat()
62       The  mknodat() system call operates in exactly the same way as mknod(),
63       except for the differences described here.
64
65       If the pathname given in pathname is relative, then it  is  interpreted
66       relative  to  the  directory  referred  to by the file descriptor dirfd
67       (rather than relative to the current working directory of  the  calling
68       process, as is done by mknod() for a relative pathname).
69
70       If  pathname  is relative and dirfd is the special value AT_FDCWD, then
71       pathname is interpreted relative to the current  working  directory  of
72       the calling process (like mknod()).
73
74       If pathname is absolute, then dirfd is ignored.
75
76       See openat(2) for an explanation of the need for mknodat().
77

RETURN VALUE

79       mknod() and mknodat() return zero on success.  On error, -1 is returned
80       and errno is set to indicate the error.
81

ERRORS

83       EACCES The parent directory does not  allow  write  permission  to  the
84              process,  or  one of the directories in the path prefix of path‐
85              name did not allow search permission.   (See  also  path_resolu‐
86              tion(7).)
87
88       EBADF  (mknodat())  pathname  is relative but dirfd is neither AT_FDCWD
89              nor a valid file descriptor.
90
91       EDQUOT The user's quota of disk blocks or inodes on the filesystem  has
92              been exhausted.
93
94       EEXIST pathname  already exists.  This includes the case where pathname
95              is a symbolic link, dangling or not.
96
97       EFAULT pathname points outside your accessible address space.
98
99       EINVAL mode requested creation of something other than a regular  file,
100              device special file, FIFO or socket.
101
102       ELOOP  Too many symbolic links were encountered in resolving pathname.
103
104       ENAMETOOLONG
105              pathname was too long.
106
107       ENOENT A  directory  component  in pathname does not exist or is a dan‐
108              gling symbolic link.
109
110       ENOMEM Insufficient kernel memory was available.
111
112       ENOSPC The device containing pathname has no room for the new node.
113
114       ENOTDIR
115              A component used as a directory in pathname is not, in  fact,  a
116              directory.
117
118       ENOTDIR
119              (mknodat())  pathname is relative and dirfd is a file descriptor
120              referring to a file other than a directory.
121
122       EPERM  mode requested creation of something other than a regular  file,
123              FIFO  (named pipe), or UNIX domain socket, and the caller is not
124              privileged (Linux: does not have the CAP_MKNOD capability); also
125              returned  if the filesystem containing pathname does not support
126              the type of node requested.
127
128       EROFS  pathname refers to a file on a read-only filesystem.
129

VERSIONS

131       POSIX.1-2001 says: "The only portable use of mknod()  is  to  create  a
132       FIFO-special  file.  If mode is not S_IFIFO or dev is not 0, the behav‐
133       ior of mknod() is unspecified."  However, nowadays one should never use
134       mknod()  for  this  purpose; one should use mkfifo(3), a function espe‐
135       cially defined for this purpose.
136
137       Under Linux, mknod() cannot be used to create directories.  One  should
138       make directories with mkdir(2).
139

STANDARDS

141       POSIX.1-2008.
142

HISTORY

144       mknod()
145              SVr4, 4.4BSD, POSIX.1-2001 (but see VERSIONS).
146
147       mknodat()
148              Linux 2.6.16, glibc 2.4.  POSIX.1-2008.
149

NOTES

151       There  are  many  infelicities in the protocol underlying NFS.  Some of
152       these affect mknod() and mknodat().
153

SEE ALSO

155       mknod(1), chmod(2), chown(2), fcntl(2), mkdir(2), mount(2),  socket(2),
156       stat(2), umask(2), unlink(2), makedev(3), mkfifo(3), acl(5), path_reso‐
157       lution(7)
158
159
160
161Linux man-pages 6.05              2023-03-31                          mknod(2)
Impressum