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