Start of man-pages-NEXT: Move Changes to Changes.old
[man-pages.git] / man2 / mkdir.2
blob1b06d9449571955b97f57a6e31784de46bb5f1d8
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 .\" SPDX-License-Identifier: GPL-1.0-or-later
7 .\"
8 .TH MKDIR 2 2022-09-09 "Linux man-pages (unreleased)"
9 .SH NAME
10 mkdir, mkdirat \- create a directory
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ", " \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <sys/stat.h>
17 .\" .B #include <unistd.h>
18 .PP
19 .BI "int mkdir(const char *" pathname ", mode_t " mode );
20 .PP
21 .BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
22 .B #include <sys/stat.h>
23 .PP
24 .BI "int mkdirat(int " dirfd ", const char *" pathname ", mode_t " mode );
25 .fi
26 .PP
27 .RS -4
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
30 .RE
31 .PP
32 .BR mkdirat ():
33 .nf
34     Since glibc 2.10:
35         _POSIX_C_SOURCE >= 200809L
36     Before glibc 2.10:
37         _ATFILE_SOURCE
38 .fi
39 .SH DESCRIPTION
40 .BR mkdir ()
41 attempts to create a directory named
42 .IR pathname .
43 .PP
44 The argument
45 .I mode
46 specifies the mode for the new directory (see
47 .BR inode (7)).
48 It is modified by the process's
49 .I umask
50 in the usual way: in the absence of a default ACL, the mode of the
51 created directory is
52 .RI ( mode " & \(ti" umask " & 0777)."
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.
57 .PP
58 The newly created directory will be owned by the effective user ID of the
59 process.
60 If the directory containing the file has the set-group-ID
61 bit set, or if the filesystem is mounted with BSD group semantics
62 .RI ( "mount \-o bsdgroups"
63 or, synonymously
64 .IR "mount \-o grpid" ),
65 the new directory will inherit the group ownership from its parent;
66 otherwise it will be owned by the effective group ID of the process.
67 .PP
68 If the parent directory has the set-group-ID bit set, then so will the
69 newly created directory.
70 .\"
71 .\"
72 .SS mkdirat()
73 The
74 .BR mkdirat ()
75 system call operates in exactly the same way as
76 .BR mkdir (),
77 except for the differences described here.
78 .PP
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
86 .BR mkdir ()
87 for a relative pathname).
88 .PP
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
99 .BR mkdir ()).
102 .I pathname
103 is absolute, then
104 .I dirfd
105 is ignored.
108 .BR openat (2)
109 for an explanation of the need for
110 .BR mkdirat ().
111 .SH RETURN VALUE
112 .BR mkdir ()
114 .BR mkdirat ()
115 return zero on success.
116 On error, \-1 is returned and
117 .I errno
118 is set to indicate the error.
119 .SH ERRORS
121 .B EACCES
122 The parent directory does not allow write permission to the process,
123 or one of the directories in
124 .I pathname
125 did not allow search permission.
126 (See also
127 .BR path_resolution (7).)
129 .B EBADF
130 .RB ( mkdirat ())
131 .I pathname
132 is relative but
133 .I dirfd
134 is neither
135 .B AT_FDCWD
136 nor a valid file descriptor.
138 .B EDQUOT
139 The user's quota of disk blocks or inodes on the filesystem has been
140 exhausted.
142 .B EEXIST
143 .I pathname
144 already exists (not necessarily as a directory).
145 This includes the case where
146 .I pathname
147 is a symbolic link, dangling or not.
149 .B EFAULT
150 .IR pathname " points outside your accessible address space."
152 .B EINVAL
153 The final component ("basename") of the new directory's
154 .I pathname
155 is invalid
156 (e.g., it contains characters not permitted by the underlying filesystem).
158 .B ELOOP
159 Too many symbolic links were encountered in resolving
160 .IR pathname .
162 .B EMLINK
163 The number of links to the parent directory would exceed
164 .BR LINK_MAX .
166 .B ENAMETOOLONG
167 .IR pathname " was too long."
169 .B ENOENT
170 A directory component in
171 .I pathname
172 does not exist or is a dangling symbolic link.
174 .B ENOMEM
175 Insufficient kernel memory was available.
177 .B ENOSPC
178 The device containing
179 .I pathname
180 has no room for the new directory.
182 .B ENOSPC
183 The new directory cannot be created because the user's disk quota is
184 exhausted.
186 .B ENOTDIR
187 A component used as a directory in
188 .I pathname
189 is not, in fact, a directory.
191 .B ENOTDIR
192 .RB ( mkdirat ())
193 .I pathname
194 is relative and
195 .I dirfd
196 is a file descriptor referring to a file other than a directory.
198 .B EPERM
199 The filesystem containing
200 .I pathname
201 does not support the creation of directories.
203 .B EROFS
204 .I pathname
205 refers to a file on a read-only filesystem.
206 .SH VERSIONS
207 .BR mkdirat ()
208 was added to Linux in kernel 2.6.16;
209 library support was added to glibc in version 2.4.
210 .SH STANDARDS
211 .BR mkdir ():
212 SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
213 .\" SVr4 documents additional EIO, EMULTIHOP
215 .BR mkdirat ():
216 POSIX.1-2008.
217 .SH NOTES
218 Under Linux, apart from the permission bits, the
219 .B S_ISVTX
220 .I mode
221 bit is also honored.
223 There are many infelicities in the protocol underlying NFS.
224 Some of these affect
225 .BR mkdir ().
226 .SS Glibc notes
227 On older kernels where
228 .BR mkdirat ()
229 is unavailable, the glibc wrapper function falls back to the use of
230 .BR mkdir ().
231 When
232 .I pathname
233 is a relative pathname,
234 glibc constructs a pathname based on the symbolic link in
235 .I /proc/self/fd
236 that corresponds to the
237 .I dirfd
238 argument.
239 .SH SEE ALSO
240 .BR mkdir (1),
241 .BR chmod (2),
242 .BR chown (2),
243 .BR mknod (2),
244 .BR mount (2),
245 .BR rmdir (2),
246 .BR stat (2),
247 .BR umask (2),
248 .BR unlink (2),
249 .BR acl (5),
250 .BR path_resolution (7)