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