1MKNOD(2) Linux Programmer's Manual MKNOD(2)
2
3
4
6 mknod - create a special or ordinary file
7
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13
14 int mknod(const char *pathname, mode_t mode, dev_t dev);
15
17 The system call mknod() creates a filesystem node (file, device special
18 file or named pipe) named pathname, with attributes specified by mode
19 and dev.
20
21 The mode argument specifies both the permissions to use and the type of
22 node to be created. It should be a combination (using bitwise OR) of
23 one of the file types listed below and the permissions for the new
24 node.
25
26 The permissions are modified by the process's umask in the usual way:
27 the permissions of the created node are (mode & ~umask).
28
29 The file type must be one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO or
30 S_IFSOCK to specify a normal file (which will be created empty), char‐
31 acter special file, block special file, FIFO (named pipe), or Unix
32 domain socket, respectively. (Zero file type is equivalent to type
33 S_IFREG.)
34
35 If the file type is S_IFCHR or S_IFBLK then dev specifies the major and
36 minor numbers of the newly created device special file; otherwise it is
37 ignored.
38
39 If pathname already exists, or is a symbolic link, this call fails with
40 an EEXIST error.
41
42 The newly created node will be owned by the effective user ID of the
43 process. If the directory containing the node has the set-group-ID bit
44 set, or if the filesystem is mounted with BSD group semantics, the new
45 node will inherit the group ownership from its parent directory; other‐
46 wise it will be owned by the effective group ID of the process.
47
49 mknod() returns zero on success, or -1 if an error occurred (in which
50 case, errno is set appropriately).
51
53 EACCES The parent directory does not allow write permission to the
54 process, or one of the directories in the path prefix of path‐
55 name did not allow search permission. (See also path_resolu‐
56 tion(2).)
57
58 EEXIST pathname already exists.
59
60 EFAULT pathname points outside your accessible address space.
61
62 EINVAL mode requested creation of something other than a normal file,
63 device special file, FIFO or socket.
64
65 ELOOP Too many symbolic links were encountered in resolving pathname.
66
67 ENAMETOOLONG
68 pathname was too long.
69
70 ENOENT A directory component in pathname does not exist or is a dan‐
71 gling symbolic link.
72
73 ENOMEM Insufficient kernel memory was available.
74
75 ENOSPC The device containing pathname has no room for the new node.
76
77 ENOTDIR
78 A component used as a directory in pathname is not, in fact, a
79 directory.
80
81 EPERM mode requested creation of something other than a regular file,
82 FIFO (named pipe), or Unix domain socket, and the caller is not
83 privileged (Linux: does not have the CAP_MKNOD capability); also
84 returned if the filesystem containing pathname does not support
85 the type of node requested.
86
87 EROFS pathname refers to a file on a read-only filesystem.
88
90 SVr4, 4.4BSD, POSIX.1-2001 (but see below).
91
93 POSIX.1-2001 says: "The only portable use of mknod() is to create a
94 FIFO-special file. If mode is not S_IFIFO or dev is not 0, the behavior
95 of mknod() is unspecified."
96
97 Under Linux, this call cannot be used to create directories. One
98 should make directories with mkdir(2), and FIFOs with mkfifo(2).
99
100 There are many infelicities in the protocol underlying NFS. Some of
101 these affect mknod().
102
104 fcntl(2), mkdir(2), mknodat(2), mount(2), path_resolution(2),
105 socket(2), stat(2), umask(2), unlink(2), mkfifo(3)
106
107
108
109Linux 2.6.7 2004-06-23 MKNOD(2)