OSDN Git Service

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