]>
Commit | Line | Data |
---|---|---|
fea681da MK |
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 | |
d9bfdb9c | 7 | .\" Public License. It comes with NO WARRANTY. |
fea681da MK |
8 | .\" |
9 | .\" Modified 1996-08-18 by urs | |
10 | .\" Modified 2003-04-23 by Michael Kerrisk | |
c11b1abf | 11 | .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 12 | .\" |
cc4615cc | 13 | .TH MKNOD 2 2007-07-26 "Linux" "Linux Programmer's Manual" |
fea681da MK |
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 | |
cc4615cc MK |
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 | |
fea681da MK |
33 | .SH DESCRIPTION |
34 | The system call | |
e511ffb6 | 35 | .BR mknod () |
fea681da MK |
36 | creates a filesystem 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 | |
0daa9e92 | 52 | .I umask |
fea681da | 53 | in the usual way: the permissions of the created node are |
66ee0c7e | 54 | .IR "(mode & ~umask)" . |
fea681da MK |
55 | |
56 | The file type must be one of | |
57 | .BR S_IFREG , | |
58 | .BR S_IFCHR , | |
59 | .BR S_IFBLK , | |
0daa9e92 | 60 | .B S_IFIFO |
fea681da | 61 | or |
0daa9e92 | 62 | .B S_IFSOCK |
fea681da MK |
63 | .\" (S_IFSOCK since Linux 1.2.4) |
64 | to specify a normal file (which will be created empty), character | |
65 | special file, block special file, FIFO (named pipe), or Unix domain socket, | |
66 | respectively. | |
682edefb MK |
67 | (Zero file type is equivalent to type |
68 | .BR S_IFREG .) | |
fea681da MK |
69 | |
70 | If the file type is | |
71 | .BR S_IFCHR " or " S_IFBLK | |
72 | then | |
73 | .I dev | |
74 | specifies the major and minor numbers of the newly created device | |
75 | special file; otherwise it is ignored. | |
76 | ||
77 | If | |
78 | .I pathname | |
682edefb MK |
79 | already exists, or is a symbolic link, this call fails with an |
80 | .B EEXIST | |
81 | error. | |
fea681da MK |
82 | |
83 | The newly created node will be owned by the effective user ID of the | |
c13182ef MK |
84 | process. |
85 | If the directory containing the node has the set-group-ID | |
fea681da MK |
86 | bit set, or if the filesystem is mounted with BSD group semantics, the |
87 | new node will inherit the group ownership from its parent directory; | |
88 | otherwise it will be owned by the effective group ID of the process. | |
89 | .SH "RETURN VALUE" | |
e511ffb6 | 90 | .BR mknod () |
fea681da MK |
91 | returns zero on success, or \-1 if an error occurred (in which case, |
92 | .I errno | |
93 | is set appropriately). | |
94 | .SH ERRORS | |
95 | .TP | |
96 | .B EACCES | |
97 | The parent directory does not allow write permission to the process, | |
98 | or one of the directories in the path prefix of | |
0daa9e92 | 99 | .I pathname |
fea681da MK |
100 | did not allow search permission. |
101 | (See also | |
ad7cc990 | 102 | .BR path_resolution (7).) |
fea681da MK |
103 | .TP |
104 | .B EEXIST | |
105 | .I pathname | |
106 | already exists. | |
107 | .TP | |
108 | .B EFAULT | |
109 | .IR pathname " points outside your accessible address space." | |
110 | .TP | |
111 | .B EINVAL | |
112 | .I mode | |
113 | requested creation of something other than a normal file, device | |
114 | special file, FIFO or socket. | |
115 | .TP | |
116 | .B ELOOP | |
117 | Too many symbolic links were encountered in resolving | |
118 | .IR pathname . | |
119 | .TP | |
120 | .B ENAMETOOLONG | |
121 | .IR pathname " was too long." | |
122 | .TP | |
123 | .B ENOENT | |
124 | A directory component in | |
125 | .I pathname | |
126 | does not exist or is a dangling symbolic link. | |
127 | .TP | |
128 | .B ENOMEM | |
129 | Insufficient kernel memory was available. | |
130 | .TP | |
131 | .B ENOSPC | |
132 | The device containing | |
133 | .I pathname | |
134 | has no room for the new node. | |
135 | .TP | |
136 | .B ENOTDIR | |
137 | A component used as a directory in | |
138 | .I pathname | |
139 | is not, in fact, a directory. | |
140 | .TP | |
141 | .B EPERM | |
142 | .I mode | |
143 | requested creation of something other than a regular file, | |
144 | FIFO (named pipe), or Unix domain socket, and the caller | |
145 | is not privileged (Linux: does not have the | |
146 | .B CAP_MKNOD | |
6e5a7309 MK |
147 | capability); |
148 | .\" For Unix domain sockets and regular files, EPERM is only returned in | |
149 | .\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can | |
150 | .\" use mknod() to make these files. | |
151 | also returned if the filesystem containing | |
fea681da MK |
152 | .I pathname |
153 | does not support the type of node requested. | |
154 | .TP | |
155 | .B EROFS | |
156 | .I pathname | |
157 | refers to a file on a read-only filesystem. | |
158 | .SH "CONFORMING TO" | |
c13182ef | 159 | SVr4, 4.4BSD, POSIX.1-2001 (but see below). |
97c1eac8 MK |
160 | .\" The Linux version differs from the SVr4 version in that it |
161 | .\" does not require root permission to create pipes, also in that no | |
162 | .\" EMULTIHOP, ENOLINK, or EINTR error is documented. | |
fea681da | 163 | .SH NOTES |
97c1eac8 | 164 | POSIX.1-2001 says: "The only portable use of |
fea681da | 165 | .BR mknod () |
c13182ef MK |
166 | is to create a FIFO-special file. |
167 | If | |
fea681da MK |
168 | .I mode |
169 | is not S_IFIFO or | |
170 | .I dev | |
171 | is not 0, the behavior of | |
172 | .BR mknod () | |
173 | is unspecified." | |
174 | ||
175 | Under Linux, this call cannot be used to create directories. | |
176 | One should make directories with | |
8478ee02 | 177 | .BR mkdir (2), |
fea681da | 178 | and FIFOs with |
28dfb19d | 179 | .BR mkfifo (3). |
fea681da MK |
180 | .\" Unix domain sockets with .BR socket " (and " bind ), |
181 | ||
c13182ef MK |
182 | There are many infelicities in the protocol underlying NFS. |
183 | Some of these affect | |
e511ffb6 | 184 | .BR mknod (). |
fea681da MK |
185 | .SH "SEE ALSO" |
186 | .BR fcntl (2), | |
187 | .BR mkdir (2), | |
5b425567 | 188 | .BR mknodat (2), |
fea681da | 189 | .BR mount (2), |
fea681da MK |
190 | .BR socket (2), |
191 | .BR stat (2), | |
192 | .BR umask (2), | |
193 | .BR unlink (2), | |
ad7cc990 MK |
194 | .BR mkfifo (3), |
195 | .BR path_resolution (7) |