OSDN Git Service

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