signal.7: Since Linux 3.8, read(2) on an inotify FD is restartable with SA_RESTART
[man-pages.git] / man2 / mkdir.2
blob3fe744db75772a7d9f6901bc15706e13bc8f36c3
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt
3 .\"             and Copyright (C) 1993,1994 Ian Jackson
4 .\"             and Copyright (C) 2006, 2014 Michael Kerrisk
5 .\"
6 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
7 .\" You may distribute it under the terms of the GNU General
8 .\" Public License. It comes with NO WARRANTY.
9 .\" %%%LICENSE_END
10 .\"
11 .TH MKDIR 2 2017-05-03 "Linux" "Linux Programmer's Manual"
12 .SH NAME
13 mkdir, mkdirat \- create a directory
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 );
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 _POSIX_C_SOURCE\ >=\ 200809L
40 .TP
41 Before glibc 2.10:
42 _ATFILE_SOURCE
43 .RE
44 .ad
45 .PD
46 .fi
47 .SH DESCRIPTION
48 .BR mkdir ()
49 attempts to create a directory named
50 .IR pathname .
52 The argument
53 .I mode
54 specifies the mode for the new directory (see
55 .BR inode (7)).
56 It is modified by the process's
57 .I umask
58 in the usual way: in the absence of a default ACL, the mode of the
59 created directory is
60 .RI ( mode " & ~" umask " & 0777)."
61 Whether other
62 .I mode
63 bits are honored for the created directory depends on the operating system.
64 For Linux, see NOTES below.
66 The newly created directory will be owned by the effective user ID of the
67 process.
68 If the directory containing the file has the set-group-ID
69 bit set, or if the filesystem is mounted with BSD group semantics
70 .RI ( "mount -o bsdgroups"
71 or, synonymously
72 .IR "mount -o grpid" ),
73 the new directory will inherit the group ownership from its parent;
74 otherwise it will be owned by the effective group ID of the process.
76 If the parent directory has the set-group-ID bit set, then so will the
77 newly created directory.
78 .\"
79 .\"
80 .SS mkdirat()
81 The
82 .BR mkdirat ()
83 system call operates in exactly the same way as
84 .BR mkdir (),
85 except for the differences described here.
87 If the pathname given in
88 .I pathname
89 is relative, then it is interpreted relative to the directory
90 referred to by the file descriptor
91 .I dirfd
92 (rather than relative to the current working directory of
93 the calling process, as is done by
94 .BR mkdir ()
95 for a relative pathname).
98 .I pathname
99 is relative and
100 .I dirfd
101 is the special value
102 .BR AT_FDCWD ,
103 then
104 .I pathname
105 is interpreted relative to the current working
106 directory of the calling process (like
107 .BR mkdir ()).
110 .I pathname
111 is absolute, then
112 .I dirfd
113 is ignored.
116 .BR openat (2)
117 for an explanation of the need for
118 .BR mkdirat ().
119 .SH RETURN VALUE
120 .BR mkdir ()
122 .BR mkdirat ()
123 return zero on success, or \-1 if an error occurred (in which case,
124 .I errno
125 is set appropriately).
126 .SH ERRORS
128 .B EACCES
129 The parent directory does not allow write permission to the process,
130 or one of the directories in
131 .I pathname
132 did not allow search permission.
133 (See also
134 .BR path_resolution (7).)
136 .B EDQUOT
137 The user's quota of disk blocks or inodes on the filesystem has been
138 exhausted.
140 .B EEXIST
141 .I pathname
142 already exists (not necessarily as a directory).
143 This includes the case where
144 .I pathname
145 is a symbolic link, dangling or not.
147 .B EFAULT
148 .IR pathname " points outside your accessible address space."
150 .B ELOOP
151 Too many symbolic links were encountered in resolving
152 .IR pathname .
154 .B EMLINK
155 The number of links to the parent directory would exceed
156 .BR LINK_MAX .
158 .B ENAMETOOLONG
159 .IR pathname " was too long."
161 .B ENOENT
162 A directory component in
163 .I pathname
164 does not exist or is a dangling symbolic link.
166 .B ENOMEM
167 Insufficient kernel memory was available.
169 .B ENOSPC
170 The device containing
171 .I pathname
172 has no room for the new directory.
174 .B ENOSPC
175 The new directory cannot be created because the user's disk quota is
176 exhausted.
178 .B ENOTDIR
179 A component used as a directory in
180 .I pathname
181 is not, in fact, a directory.
183 .B EPERM
184 The filesystem containing
185 .I pathname
186 does not support the creation of directories.
188 .B EROFS
189 .I pathname
190 refers to a file on a read-only filesystem.
192 The following additional errors can occur for
193 .BR mkdirat ():
195 .B EBADF
196 .I dirfd
197 is not a valid file descriptor.
199 .B ENOTDIR
200 .I pathname
201 is relative and
202 .I dirfd
203 is a file descriptor referring to a file other than a directory.
204 .SH VERSIONS
205 .BR mkdirat ()
206 was added to Linux in kernel 2.6.16;
207 library support was added to glibc in version 2.4.
208 .SH CONFORMING TO
209 .BR mkdir ():
210 SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
211 .\" SVr4 documents additional EIO, EMULTIHOP
213 .BR mkdirat ():
214 POSIX.1-2008.
215 .SH NOTES
216 Under Linux, apart from the permission bits, the
217 .B S_ISVTX
218 .I mode
219 bit is also honored.
221 There are many infelicities in the protocol underlying NFS.
222 Some of these affect
223 .BR mkdir ().
224 .SS Glibc notes
225 On older kernels where
226 .BR mkdirat ()
227 is unavailable, the glibc wrapper function falls back to the use of
228 .BR mkdir ().
229 When
230 .I pathname
231 is a relative pathname,
232 glibc constructs a pathname based on the symbolic link in
233 .IR /proc/self/fd
234 that corresponds to the
235 .IR dirfd
236 argument.
237 .SH SEE ALSO
238 .BR mkdir (1),
239 .BR chmod (2),
240 .BR chown (2),
241 .BR mknod (2),
242 .BR mount (2),
243 .BR rmdir (2),
244 .BR stat (2),
245 .BR umask (2),
246 .BR unlink (2),
247 .BR acl (5)
248 .BR path_resolution (7)