OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / man2 / mknod.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"                               1993 Michael Haardt
3 .\"                               1993,1994 Ian Jackson.
4 .\"
5 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
6 .\" You may distribute it under the terms of the GNU General
7 .\" Public License. It comes with NO WARRANTY.
8 .\" %%%LICENSE_END
9 .\"
10 .\" Modified 1996-08-18 by urs
11 .\" Modified 2003-04-23 by Michael Kerrisk
12 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
13 .\"
14 .TH MKNOD 2 2013-01-27 "Linux" "Linux Programmer's Manual"
15 .SH NAME
16 mknod \- create a special or ordinary file
17 .SH SYNOPSIS
18 .nf
19 .B #include <sys/types.h>
20 .B #include <sys/stat.h>
21 .B #include <fcntl.h>
22 .B #include <unistd.h>
23 .sp
24 .BI "int mknod(const char *" pathname ", mode_t " mode ", dev_t " dev );
25 .fi
26 .sp
27 .in -4n
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
30 .in
31 .sp
32 .BR mknod ():
33 .ad l
34 .RS 4
35 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
36 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
37 .RE
38 .ad
39 .SH DESCRIPTION
40 The system call
41 .BR mknod ()
42 creates a file system node (file, device special file or
43 named pipe) named
44 .IR pathname ,
45 with attributes specified by
46 .I mode
47 and
48 .IR dev .
49
50 The
51 .I mode
52 argument specifies both the permissions to use and the type of node
53 to be created.
54 It should be a combination (using bitwise OR) of one of the file types
55 listed below and the permissions for the new node.
56
57 The permissions are modified by the process's
58 .I umask
59 in the usual way: the permissions of the created node are
60 .IR "(mode & ~umask)" .
61
62 The file type must be one of
63 .BR S_IFREG ,
64 .BR S_IFCHR ,
65 .BR S_IFBLK ,
66 .B S_IFIFO
67 or
68 .B S_IFSOCK
69 .\" (S_IFSOCK since Linux 1.2.4)
70 to specify a regular file (which will be created empty), character
71 special file, block special file, FIFO (named pipe), or UNIX domain socket,
72 respectively.
73 (Zero file type is equivalent to type
74 .BR S_IFREG .)
75
76 If the file type is
77 .B S_IFCHR
78 or
79 .B S_IFBLK
80 then
81 .I dev
82 specifies the major and minor numbers of the newly created device
83 special file
84 .RB ( makedev (3)
85 may be useful to build the value for
86 .IR dev );
87 otherwise it is ignored.
88
89 If
90 .I pathname
91 already exists, or is a symbolic link, this call fails with an
92 .B EEXIST
93 error.
94
95 The newly created node will be owned by the effective user ID of the
96 process.
97 If the directory containing the node has the set-group-ID
98 bit set, or if the file system is mounted with BSD group semantics, the
99 new node will inherit the group ownership from its parent directory;
100 otherwise it will be owned by the effective group ID of the process.
101 .SH RETURN VALUE
102 .BR mknod ()
103 returns zero on success, or \-1 if an error occurred (in which case,
104 .I errno
105 is set appropriately).
106 .SH ERRORS
107 .TP
108 .B EACCES
109 The parent directory does not allow write permission to the process,
110 or one of the directories in the path prefix of
111 .I pathname
112 did not allow search permission.
113 (See also
114 .BR path_resolution (7).)
115 .TP
116 .B EDQUOT
117 The user's quota of disk blocks or inodes on the file system has been
118 exhausted.
119 .TP
120 .B EEXIST
121 .I pathname
122 already exists.
123 This includes the case where
124 .I pathname
125 is a symbolic link, dangling or not.
126 .TP
127 .B EFAULT
128 .IR pathname " points outside your accessible address space."
129 .TP
130 .B EINVAL
131 .I mode
132 requested creation of something other than a regular file, device
133 special file, FIFO or socket.
134 .TP
135 .B ELOOP
136 Too many symbolic links were encountered in resolving
137 .IR pathname .
138 .TP
139 .B ENAMETOOLONG
140 .IR pathname " was too long."
141 .TP
142 .B ENOENT
143 A directory component in
144 .I pathname
145 does not exist or is a dangling symbolic link.
146 .TP
147 .B ENOMEM
148 Insufficient kernel memory was available.
149 .TP
150 .B ENOSPC
151 The device containing
152 .I pathname
153 has no room for the new node.
154 .TP
155 .B ENOTDIR
156 A component used as a directory in
157 .I pathname
158 is not, in fact, a directory.
159 .TP
160 .B EPERM
161 .I mode
162 requested creation of something other than a regular file,
163 FIFO (named pipe), or UNIX domain socket, and the caller
164 is not privileged (Linux: does not have the
165 .B CAP_MKNOD
166 capability);
167 .\" For UNIX domain sockets and regular files, EPERM is only returned in
168 .\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
169 .\" use mknod() to make these files.
170 also returned if the file system containing
171 .I pathname
172 does not support the type of node requested.
173 .TP
174 .B EROFS
175 .I pathname
176 refers to a file on a read-only file system.
177 .SH CONFORMING TO
178 SVr4, 4.4BSD, POSIX.1-2001 (but see below).
179 .\" The Linux version differs from the SVr4 version in that it
180 .\" does not require root permission to create pipes, also in that no
181 .\" EMULTIHOP, ENOLINK, or EINTR error is documented.
182 .SH NOTES
183 POSIX.1-2001 says: "The only portable use of
184 .BR mknod ()
185 is to create a FIFO-special file.
186 If
187 .I mode
188 is not
189 .B S_IFIFO
190 or
191 .I dev
192 is not 0, the behavior of
193 .BR mknod ()
194 is unspecified."
195 However, nowadays one should never use
196 .BR mknod ()
197 for this purpose; one should use
198 .BR mkfifo (3),
199 a function especially defined for this purpose.
200
201 Under Linux, this call cannot be used to create directories.
202 One should make directories with
203 .BR mkdir (2).
204 .\" and one should make UNIX domain sockets with socket(2) and bind(2).
205
206 There are many infelicities in the protocol underlying NFS.
207 Some of these affect
208 .BR mknod ().
209 .SH SEE ALSO
210 .BR chmod (2),
211 .BR chown (2),
212 .BR fcntl (2),
213 .BR mkdir (2),
214 .BR mknodat (2),
215 .BR mount (2),
216 .BR socket (2),
217 .BR stat (2),
218 .BR umask (2),
219 .BR unlink (2),
220 .BR makedev (3),
221 .BR mkfifo (3),
222 .BR path_resolution (7)