]>
Commit | Line | Data |
---|---|---|
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 | 17 | mknod, 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 |
35 | Feature 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 |
49 | The system call | |
e511ffb6 | 50 | .BR mknod () |
ba96eb7d | 51 | creates a filesystem node (file, device special file, or |
fea681da MK |
52 | named pipe) named |
53 | .IR pathname , | |
54 | with attributes specified by | |
55 | .I mode | |
56 | and | |
57 | .IR dev . | |
efeece04 | 58 | .PP |
fea681da MK |
59 | The |
60 | .I mode | |
9fcca5a0 | 61 | argument specifies both the file mode to use and the type of node |
fea681da MK |
62 | to be created. |
63 | It should be a combination (using bitwise OR) of one of the file types | |
9fcca5a0 | 64 | listed below and zero or more of the file mode bits listed in |
e6fc1596 | 65 | .BR inode (7). |
efeece04 | 66 | .PP |
9fcca5a0 | 67 | The file mode is modified by the process's |
0daa9e92 | 68 | .I umask |
a57c98a0 | 69 | in the usual way: in the absence of a default ACL, the permissions of the |
5d817eb4 AG |
70 | created node are |
71 | .RI ( mode " & ~" umask ). | |
efeece04 | 72 | .PP |
fea681da MK |
73 | The file type must be one of |
74 | .BR S_IFREG , | |
75 | .BR S_IFCHR , | |
76 | .BR S_IFBLK , | |
43ff9b28 | 77 | .BR S_IFIFO , |
fea681da | 78 | or |
0daa9e92 | 79 | .B S_IFSOCK |
fea681da | 80 | .\" (S_IFSOCK since Linux 1.2.4) |
21035964 | 81 | to specify a regular file (which will be created empty), character |
008f1ecc | 82 | special file, block special file, FIFO (named pipe), or UNIX domain socket, |
fea681da | 83 | respectively. |
682edefb MK |
84 | (Zero file type is equivalent to type |
85 | .BR S_IFREG .) | |
efeece04 | 86 | .PP |
fea681da | 87 | If the file type is |
90a04948 MK |
88 | .B S_IFCHR |
89 | or | |
df53e85b | 90 | .BR S_IFBLK , |
fea681da MK |
91 | then |
92 | .I dev | |
93 | specifies the major and minor numbers of the newly created device | |
6437f56b MK |
94 | special file |
95 | .RB ( makedev (3) | |
96 | may be useful to build the value for | |
97 | .IR dev ); | |
98 | otherwise it is ignored. | |
efeece04 | 99 | .PP |
fea681da MK |
100 | If |
101 | .I pathname | |
682edefb MK |
102 | already exists, or is a symbolic link, this call fails with an |
103 | .B EEXIST | |
104 | error. | |
efeece04 | 105 | .PP |
fea681da | 106 | The newly created node will be owned by the effective user ID of the |
c13182ef MK |
107 | process. |
108 | If the directory containing the node has the set-group-ID | |
9ee4a2b6 | 109 | bit set, or if the filesystem is mounted with BSD group semantics, the |
fea681da MK |
110 | new node will inherit the group ownership from its parent directory; |
111 | otherwise it will be owned by the effective group ID of the process. | |
60e7d95b MK |
112 | .\" |
113 | .\" | |
114 | .SS mknodat() | |
115 | The | |
116 | .BR mknodat () | |
117 | system call operates in exactly the same way as | |
bf7bc8b8 | 118 | .BR mknod (), |
60e7d95b | 119 | except for the differences described here. |
efeece04 | 120 | .PP |
60e7d95b MK |
121 | If the pathname given in |
122 | .I pathname | |
123 | is relative, then it is interpreted relative to the directory | |
124 | referred to by the file descriptor | |
125 | .I dirfd | |
126 | (rather than relative to the current working directory of | |
127 | the calling process, as is done by | |
bf7bc8b8 | 128 | .BR mknod () |
60e7d95b | 129 | for a relative pathname). |
efeece04 | 130 | .PP |
60e7d95b MK |
131 | If |
132 | .I pathname | |
133 | is relative and | |
134 | .I dirfd | |
135 | is the special value | |
136 | .BR AT_FDCWD , | |
137 | then | |
138 | .I pathname | |
139 | is interpreted relative to the current working | |
140 | directory of the calling process (like | |
bf7bc8b8 | 141 | .BR mknod ()). |
efeece04 | 142 | .PP |
60e7d95b MK |
143 | If |
144 | .I pathname | |
145 | is absolute, then | |
146 | .I dirfd | |
147 | is ignored. | |
148 | .PP | |
149 | See | |
150 | .BR openat (2) | |
151 | for an explanation of the need for | |
152 | .BR mknodat (). | |
47297adb | 153 | .SH RETURN VALUE |
e511ffb6 | 154 | .BR mknod () |
60e7d95b MK |
155 | and |
156 | .BR mknodat () | |
157 | return zero on success, or \-1 if an error occurred (in which case, | |
fea681da MK |
158 | .I errno |
159 | is set appropriately). | |
160 | .SH ERRORS | |
161 | .TP | |
162 | .B EACCES | |
163 | The parent directory does not allow write permission to the process, | |
164 | or one of the directories in the path prefix of | |
0daa9e92 | 165 | .I pathname |
fea681da MK |
166 | did not allow search permission. |
167 | (See also | |
ad7cc990 | 168 | .BR path_resolution (7).) |
fea681da | 169 | .TP |
a1f01685 | 170 | .B EDQUOT |
9ee4a2b6 | 171 | The user's quota of disk blocks or inodes on the filesystem has been |
a1f01685 MH |
172 | exhausted. |
173 | .TP | |
fea681da MK |
174 | .B EEXIST |
175 | .I pathname | |
176 | already exists. | |
9d6299e8 MK |
177 | This includes the case where |
178 | .I pathname | |
179 | is 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 | 186 | requested creation of something other than a regular file, device |
fea681da MK |
187 | special file, FIFO or socket. |
188 | .TP | |
189 | .B ELOOP | |
190 | Too 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 | |
197 | A directory component in | |
198 | .I pathname | |
199 | does not exist or is a dangling symbolic link. | |
200 | .TP | |
201 | .B ENOMEM | |
202 | Insufficient kernel memory was available. | |
203 | .TP | |
204 | .B ENOSPC | |
205 | The device containing | |
206 | .I pathname | |
207 | has no room for the new node. | |
208 | .TP | |
209 | .B ENOTDIR | |
210 | A component used as a directory in | |
211 | .I pathname | |
212 | is not, in fact, a directory. | |
213 | .TP | |
214 | .B EPERM | |
215 | .I mode | |
216 | requested creation of something other than a regular file, | |
008f1ecc | 217 | FIFO (named pipe), or UNIX domain socket, and the caller |
fea681da MK |
218 | is not privileged (Linux: does not have the |
219 | .B CAP_MKNOD | |
6e5a7309 | 220 | capability); |
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 | 224 | also returned if the filesystem containing |
fea681da MK |
225 | .I pathname |
226 | does not support the type of node requested. | |
227 | .TP | |
228 | .B EROFS | |
229 | .I pathname | |
9ee4a2b6 | 230 | refers to a file on a read-only filesystem. |
60e7d95b MK |
231 | .PP |
232 | The following additional errors can occur for | |
233 | .BR mknodat (): | |
234 | .TP | |
235 | .B EBADF | |
236 | .I dirfd | |
237 | is not a valid file descriptor. | |
238 | .TP | |
239 | .B ENOTDIR | |
240 | .I pathname | |
241 | is relative and | |
242 | .I dirfd | |
243 | is a file descriptor referring to a file other than a directory. | |
244 | .SH VERSIONS | |
245 | .BR mknodat () | |
246 | was added to Linux in kernel 2.6.16; | |
247 | library support was added to glibc in version 2.4. | |
47297adb | 248 | .SH CONFORMING TO |
60e7d95b | 249 | .BR mknod (): |
55854bb8 | 250 | SVr4, 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 (): |
256 | POSIX.1-2008. | |
fea681da | 257 | .SH NOTES |
97c1eac8 | 258 | POSIX.1-2001 says: "The only portable use of |
fea681da | 259 | .BR mknod () |
c13182ef MK |
260 | is to create a FIFO-special file. |
261 | If | |
fea681da | 262 | .I mode |
90a04948 MK |
263 | is not |
264 | .B S_IFIFO | |
265 | or | |
fea681da MK |
266 | .I dev |
267 | is not 0, the behavior of | |
268 | .BR mknod () | |
269 | is unspecified." | |
3920c8ca MK |
270 | However, nowadays one should never use |
271 | .BR mknod () | |
272 | for this purpose; one should use | |
273 | .BR mkfifo (3), | |
274 | a function especially defined for this purpose. | |
efeece04 | 275 | .PP |
53eeabde MK |
276 | Under Linux, |
277 | .BR mknod () | |
278 | cannot be used to create directories. | |
fea681da | 279 | One 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 |
283 | There are many infelicities in the protocol underlying NFS. |
284 | Some of these affect | |
53eeabde MK |
285 | .BR mknod () |
286 | and | |
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) |