]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" This manpage is Copyright (C) 1992 Drew Eckhardt; |
ac56b6a8 | 2 | .\" and Copyright (C) 1993 Michael Haardt |
bab907ba MK |
3 | .\" and Copyright (C) 1993,1994 Ian Jackson |
4 | .\" and Copyright (C) 2006, 2014 Michael Kerrisk | |
2297bf0e | 5 | .\" |
fd0fc519 | 6 | .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE) |
fea681da | 7 | .\" You may distribute it under the terms of the GNU General |
d9bfdb9c | 8 | .\" Public License. It comes with NO WARRANTY. |
fd0fc519 | 9 | .\" %%%LICENSE_END |
fea681da | 10 | .\" |
4b8c67d9 | 11 | .TH MKDIR 2 2017-09-15 "Linux" "Linux Programmer's Manual" |
fea681da | 12 | .SH NAME |
bab907ba | 13 | mkdir, mkdirat \- create a directory |
fea681da MK |
14 | .SH SYNOPSIS |
15 | .nf | |
16 | .B #include <sys/stat.h> | |
17 | .B #include <sys/types.h> | |
18 | .\" .B #include <unistd.h> | |
68e4db0a | 19 | .PP |
fea681da | 20 | .BI "int mkdir(const char *" pathname ", mode_t " mode ); |
f90f031e | 21 | |
bab907ba MK |
22 | .BR "#include <fcntl.h> " "/* Definition of AT_* constants */" |
23 | .B #include <sys/stat.h> | |
68e4db0a | 24 | .PP |
bab907ba MK |
25 | .BI "int mkdirat(int " dirfd ", const char *" pathname ", mode_t " mode ); |
26 | .fi | |
68e4db0a | 27 | .PP |
bab907ba MK |
28 | .in -4n |
29 | Feature Test Macro Requirements for glibc (see | |
30 | .BR feature_test_macros (7)): | |
31 | .in | |
68e4db0a | 32 | .PP |
bab907ba MK |
33 | .BR mkdirat (): |
34 | .PD 0 | |
35 | .ad l | |
36 | .RS 4 | |
37 | .TP 4 | |
38 | Since glibc 2.10: | |
b0da7b8b | 39 | _POSIX_C_SOURCE\ >=\ 200809L |
bab907ba MK |
40 | .TP |
41 | Before glibc 2.10: | |
42 | _ATFILE_SOURCE | |
43 | .RE | |
44 | .ad | |
45 | .PD | |
fea681da | 46 | .SH DESCRIPTION |
e511ffb6 | 47 | .BR mkdir () |
fea681da MK |
48 | attempts to create a directory named |
49 | .IR pathname . | |
efeece04 | 50 | .PP |
c4bb193f | 51 | The argument |
fea681da | 52 | .I mode |
5ec64a3a | 53 | specifies the mode for the new directory (see |
e6fc1596 | 54 | .BR inode (7)). |
c13182ef | 55 | It is modified by the process's |
fea681da | 56 | .I umask |
2fc8395c MK |
57 | in the usual way: in the absence of a default ACL, the mode of the |
58 | created directory is | |
5ec64a3a MK |
59 | .RI ( mode " & ~" umask " & 0777)." |
60 | Whether other | |
61 | .I mode | |
62 | bits are honored for the created directory depends on the operating system. | |
63 | For Linux, see NOTES below. | |
efeece04 | 64 | .PP |
fea681da | 65 | The newly created directory will be owned by the effective user ID of the |
c13182ef MK |
66 | process. |
67 | If the directory containing the file has the set-group-ID | |
9ee4a2b6 | 68 | bit set, or if the filesystem is mounted with BSD group semantics |
79ad39a7 MK |
69 | .RI ( "mount -o bsdgroups" |
70 | or, synonymously | |
71 | .IR "mount -o grpid" ), | |
72 | the new directory will inherit the group ownership from its parent; | |
fea681da | 73 | otherwise it will be owned by the effective group ID of the process. |
efeece04 | 74 | .PP |
f14ae16e | 75 | If the parent directory has the set-group-ID bit set, then so will the |
fea681da | 76 | newly created directory. |
bab907ba MK |
77 | .\" |
78 | .\" | |
79 | .SS mkdirat() | |
80 | The | |
81 | .BR mkdirat () | |
82 | system call operates in exactly the same way as | |
cadd38ba | 83 | .BR mkdir (), |
bab907ba | 84 | except for the differences described here. |
efeece04 | 85 | .PP |
bab907ba MK |
86 | If the pathname given in |
87 | .I pathname | |
88 | is relative, then it is interpreted relative to the directory | |
89 | referred to by the file descriptor | |
90 | .I dirfd | |
91 | (rather than relative to the current working directory of | |
92 | the calling process, as is done by | |
cadd38ba | 93 | .BR mkdir () |
bab907ba | 94 | for a relative pathname). |
efeece04 | 95 | .PP |
bab907ba MK |
96 | If |
97 | .I pathname | |
98 | is relative and | |
99 | .I dirfd | |
100 | is the special value | |
101 | .BR AT_FDCWD , | |
102 | then | |
103 | .I pathname | |
104 | is interpreted relative to the current working | |
105 | directory of the calling process (like | |
cadd38ba | 106 | .BR mkdir ()). |
efeece04 | 107 | .PP |
bab907ba MK |
108 | If |
109 | .I pathname | |
110 | is absolute, then | |
111 | .I dirfd | |
112 | is ignored. | |
113 | .PP | |
114 | See | |
115 | .BR openat (2) | |
116 | for an explanation of the need for | |
117 | .BR mkdirat (). | |
47297adb | 118 | .SH RETURN VALUE |
e511ffb6 | 119 | .BR mkdir () |
bab907ba MK |
120 | and |
121 | .BR mkdirat () | |
122 | return zero on success, or \-1 if an error occurred (in which case, | |
fea681da MK |
123 | .I errno |
124 | is set appropriately). | |
125 | .SH ERRORS | |
126 | .TP | |
127 | .B EACCES | |
128 | The parent directory does not allow write permission to the process, | |
129 | or one of the directories in | |
0daa9e92 | 130 | .I pathname |
fea681da MK |
131 | did not allow search permission. |
132 | (See also | |
ad7cc990 | 133 | .BR path_resolution (7).) |
fea681da | 134 | .TP |
a1f01685 | 135 | .B EDQUOT |
9ee4a2b6 | 136 | The user's quota of disk blocks or inodes on the filesystem has been |
a1f01685 MH |
137 | exhausted. |
138 | .TP | |
fea681da MK |
139 | .B EEXIST |
140 | .I pathname | |
141 | already exists (not necessarily as a directory). | |
142 | This includes the case where | |
143 | .I pathname | |
144 | is a symbolic link, dangling or not. | |
145 | .TP | |
146 | .B EFAULT | |
147 | .IR pathname " points outside your accessible address space." | |
148 | .TP | |
cd37d57e MK |
149 | .B EINVAL |
150 | The final component ("basename") of the new directory's | |
151 | .I pathname | |
152 | is invalid | |
153 | (e.g., it contains characters not permitted by the underlying filesystem). | |
154 | .TP | |
fea681da MK |
155 | .B ELOOP |
156 | Too many symbolic links were encountered in resolving | |
157 | .IR pathname . | |
158 | .TP | |
43537f28 MK |
159 | .B EMLINK |
160 | The number of links to the parent directory would exceed | |
161 | .BR LINK_MAX . | |
162 | .TP | |
fea681da MK |
163 | .B ENAMETOOLONG |
164 | .IR pathname " was too long." | |
165 | .TP | |
166 | .B ENOENT | |
167 | A directory component in | |
168 | .I pathname | |
169 | does not exist or is a dangling symbolic link. | |
170 | .TP | |
171 | .B ENOMEM | |
172 | Insufficient kernel memory was available. | |
173 | .TP | |
174 | .B ENOSPC | |
175 | The device containing | |
176 | .I pathname | |
177 | has no room for the new directory. | |
178 | .TP | |
179 | .B ENOSPC | |
180 | The new directory cannot be created because the user's disk quota is | |
181 | exhausted. | |
182 | .TP | |
183 | .B ENOTDIR | |
184 | A component used as a directory in | |
185 | .I pathname | |
186 | is not, in fact, a directory. | |
187 | .TP | |
188 | .B EPERM | |
9ee4a2b6 | 189 | The filesystem containing |
0daa9e92 | 190 | .I pathname |
fea681da MK |
191 | does not support the creation of directories. |
192 | .TP | |
193 | .B EROFS | |
194 | .I pathname | |
9ee4a2b6 | 195 | refers to a file on a read-only filesystem. |
bab907ba MK |
196 | .PP |
197 | The following additional errors can occur for | |
198 | .BR mkdirat (): | |
199 | .TP | |
200 | .B EBADF | |
201 | .I dirfd | |
202 | is not a valid file descriptor. | |
203 | .TP | |
204 | .B ENOTDIR | |
205 | .I pathname | |
206 | is relative and | |
207 | .I dirfd | |
208 | is a file descriptor referring to a file other than a directory. | |
209 | .SH VERSIONS | |
210 | .BR mkdirat () | |
211 | was added to Linux in kernel 2.6.16; | |
212 | library support was added to glibc in version 2.4. | |
47297adb | 213 | .SH CONFORMING TO |
bab907ba | 214 | .BR mkdir (): |
68164150 | 215 | SVr4, BSD, POSIX.1-2001, POSIX.1-2008. |
97c1eac8 | 216 | .\" SVr4 documents additional EIO, EMULTIHOP |
efeece04 | 217 | .PP |
bab907ba MK |
218 | .BR mkdirat (): |
219 | POSIX.1-2008. | |
fea681da | 220 | .SH NOTES |
5ec64a3a | 221 | Under Linux, apart from the permission bits, the |
682edefb | 222 | .B S_ISVTX |
5ec64a3a MK |
223 | .I mode |
224 | bit is also honored. | |
fea681da | 225 | .PP |
c13182ef MK |
226 | There are many infelicities in the protocol underlying NFS. |
227 | Some of these affect | |
e511ffb6 | 228 | .BR mkdir (). |
f17342a5 MK |
229 | .SS Glibc notes |
230 | On older kernels where | |
231 | .BR mkdirat () | |
232 | is unavailable, the glibc wrapper function falls back to the use of | |
233 | .BR mkdir (). | |
234 | When | |
235 | .I pathname | |
236 | is a relative pathname, | |
237 | glibc constructs a pathname based on the symbolic link in | |
238 | .IR /proc/self/fd | |
239 | that corresponds to the | |
240 | .IR dirfd | |
241 | argument. | |
47297adb | 242 | .SH SEE ALSO |
fea681da MK |
243 | .BR mkdir (1), |
244 | .BR chmod (2), | |
a3bf8022 | 245 | .BR chown (2), |
fea681da MK |
246 | .BR mknod (2), |
247 | .BR mount (2), | |
fea681da MK |
248 | .BR rmdir (2), |
249 | .BR stat (2), | |
250 | .BR umask (2), | |
ad7cc990 | 251 | .BR unlink (2), |
a57c98a0 | 252 | .BR acl (5) |
ad7cc990 | 253 | .BR path_resolution (7) |