OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / 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 2008-12-01 "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 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
33 .SH DESCRIPTION
34 The system call
35 .BR mknod ()
36 creates a file system node (file, device special file or
37 named pipe) named
38 .IR pathname ,
39 with attributes specified by
40 .I mode
41 and
42 .IR dev .
43
44 The
45 .I mode
46 argument specifies both the permissions to use and the type of node
47 to be created.
48 It should be a combination (using bitwise OR) of one of the file types
49 listed below and the permissions for the new node.
50
51 The permissions are modified by the process's
52 .I umask
53 in the usual way: the permissions of the created node are
54 .IR "(mode & ~umask)" .
55
56 The file type must be one of
57 .BR S_IFREG ,
58 .BR S_IFCHR ,
59 .BR S_IFBLK ,
60 .B S_IFIFO
61 or
62 .B S_IFSOCK
63 .\" (S_IFSOCK since Linux 1.2.4)
64 to specify a regular file (which will be created empty), character
65 special file, block special file, FIFO (named pipe), or Unix domain socket,
66 respectively.
67 (Zero file type is equivalent to type
68 .BR S_IFREG .)
69
70 If the file type is
71 .B S_IFCHR
72 or
73 .B S_IFBLK
74 then
75 .I dev
76 specifies the major and minor numbers of the newly created device
77 special file
78 .RB ( makedev (3)
79 may be useful to build the value for
80 .IR dev );
81 otherwise it is ignored.
82
83 If
84 .I pathname
85 already exists, or is a symbolic link, this call fails with an
86 .B EEXIST
87 error.
88
89 The newly created node will be owned by the effective user ID of the
90 process.
91 If the directory containing the node has the set-group-ID
92 bit set, or if the file system is mounted with BSD group semantics, the
93 new node will inherit the group ownership from its parent directory;
94 otherwise it will be owned by the effective group ID of the process.
95 .SH "RETURN VALUE"
96 .BR mknod ()
97 returns zero on success, or \-1 if an error occurred (in which case,
98 .I errno
99 is set appropriately).
100 .SH ERRORS
101 .TP
102 .B EACCES
103 The parent directory does not allow write permission to the process,
104 or one of the directories in the path prefix of
105 .I pathname
106 did not allow search permission.
107 (See also
108 .BR path_resolution (7).)
109 .TP
110 .B EEXIST
111 .I pathname
112 already exists.
113 This includes the case where
114 .I pathname
115 is a symbolic link, dangling or not.
116 .TP
117 .B EFAULT
118 .IR pathname " points outside your accessible address space."
119 .TP
120 .B EINVAL
121 .I mode
122 requested creation of something other than a regular file, device
123 special file, FIFO or socket.
124 .TP
125 .B ELOOP
126 Too many symbolic links were encountered in resolving
127 .IR pathname .
128 .TP
129 .B ENAMETOOLONG
130 .IR pathname " was too long."
131 .TP
132 .B ENOENT
133 A directory component in
134 .I pathname
135 does not exist or is a dangling symbolic link.
136 .TP
137 .B ENOMEM
138 Insufficient kernel memory was available.
139 .TP
140 .B ENOSPC
141 The device containing
142 .I pathname
143 has no room for the new node.
144 .TP
145 .B ENOTDIR
146 A component used as a directory in
147 .I pathname
148 is not, in fact, a directory.
149 .TP
150 .B EPERM
151 .I mode
152 requested creation of something other than a regular file,
153 FIFO (named pipe), or Unix domain socket, and the caller
154 is not privileged (Linux: does not have the
155 .B CAP_MKNOD
156 capability);
157 .\" For Unix domain sockets and regular files, EPERM is only returned in
158 .\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
159 .\" use mknod() to make these files.
160 also returned if the file system containing
161 .I pathname
162 does not support the type of node requested.
163 .TP
164 .B EROFS
165 .I pathname
166 refers to a file on a read-only file system.
167 .SH "CONFORMING TO"
168 SVr4, 4.4BSD, POSIX.1-2001 (but see below).
169 .\" The Linux version differs from the SVr4 version in that it
170 .\" does not require root permission to create pipes, also in that no
171 .\" EMULTIHOP, ENOLINK, or EINTR error is documented.
172 .SH NOTES
173 POSIX.1-2001 says: "The only portable use of
174 .BR mknod ()
175 is to create a FIFO-special file.
176 If
177 .I mode
178 is not
179 .B S_IFIFO
180 or
181 .I dev
182 is not 0, the behavior of
183 .BR mknod ()
184 is unspecified."
185 However, nowadays one should never use
186 .BR mknod ()
187 for this purpose; one should use
188 .BR mkfifo (3),
189 a function especially defined for this purpose.
190
191 Under Linux, this call cannot be used to create directories.
192 One should make directories with
193 .BR mkdir (2).
194 .\" and one should make Unix domain sockets with socket(2) and bind(2).
195
196 There are many infelicities in the protocol underlying NFS.
197 Some of these affect
198 .BR mknod ().
199 .SH "SEE ALSO"
200 .BR chmod (2),
201 .BR chown (2),
202 .BR fcntl (2),
203 .BR mkdir (2),
204 .BR mknodat (2),
205 .BR mount (2),
206 .BR socket (2),
207 .BR stat (2),
208 .BR umask (2),
209 .BR unlink (2),
210 .BR makedev (3),
211 .BR mkfifo (3),
212 .BR path_resolution (7)