]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/mkdir.2
mknod.2: tfix
[thirdparty/man-pages.git] / man2 / mkdir.2
CommitLineData
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 13mkdir, 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
29Feature 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
38Since glibc 2.10:
b0da7b8b 39_POSIX_C_SOURCE\ >=\ 200809L
bab907ba
MK
40.TP
41Before glibc 2.10:
42_ATFILE_SOURCE
43.RE
44.ad
45.PD
fea681da 46.SH DESCRIPTION
e511ffb6 47.BR mkdir ()
fea681da
MK
48attempts to create a directory named
49.IR pathname .
efeece04 50.PP
c4bb193f 51The argument
fea681da 52.I mode
5ec64a3a 53specifies the mode for the new directory (see
e6fc1596 54.BR inode (7)).
c13182ef 55It is modified by the process's
fea681da 56.I umask
2fc8395c
MK
57in the usual way: in the absence of a default ACL, the mode of the
58created directory is
5ec64a3a
MK
59.RI ( mode " & ~" umask " & 0777)."
60Whether other
61.I mode
62bits are honored for the created directory depends on the operating system.
63For Linux, see NOTES below.
efeece04 64.PP
fea681da 65The newly created directory will be owned by the effective user ID of the
c13182ef
MK
66process.
67If the directory containing the file has the set-group-ID
9ee4a2b6 68bit set, or if the filesystem is mounted with BSD group semantics
79ad39a7
MK
69.RI ( "mount -o bsdgroups"
70or, synonymously
71.IR "mount -o grpid" ),
72the new directory will inherit the group ownership from its parent;
fea681da 73otherwise it will be owned by the effective group ID of the process.
efeece04 74.PP
f14ae16e 75If the parent directory has the set-group-ID bit set, then so will the
fea681da 76newly created directory.
bab907ba
MK
77.\"
78.\"
79.SS mkdirat()
80The
81.BR mkdirat ()
82system call operates in exactly the same way as
cadd38ba 83.BR mkdir (),
bab907ba 84except for the differences described here.
efeece04 85.PP
bab907ba
MK
86If the pathname given in
87.I pathname
88is relative, then it is interpreted relative to the directory
89referred to by the file descriptor
90.I dirfd
91(rather than relative to the current working directory of
92the calling process, as is done by
cadd38ba 93.BR mkdir ()
bab907ba 94for a relative pathname).
efeece04 95.PP
bab907ba
MK
96If
97.I pathname
98is relative and
99.I dirfd
100is the special value
101.BR AT_FDCWD ,
102then
103.I pathname
104is interpreted relative to the current working
105directory of the calling process (like
cadd38ba 106.BR mkdir ()).
efeece04 107.PP
bab907ba
MK
108If
109.I pathname
110is absolute, then
111.I dirfd
112is ignored.
113.PP
114See
115.BR openat (2)
116for an explanation of the need for
117.BR mkdirat ().
47297adb 118.SH RETURN VALUE
e511ffb6 119.BR mkdir ()
bab907ba
MK
120and
121.BR mkdirat ()
122return zero on success, or \-1 if an error occurred (in which case,
fea681da
MK
123.I errno
124is set appropriately).
125.SH ERRORS
126.TP
127.B EACCES
128The parent directory does not allow write permission to the process,
129or one of the directories in
0daa9e92 130.I pathname
fea681da
MK
131did not allow search permission.
132(See also
ad7cc990 133.BR path_resolution (7).)
fea681da 134.TP
a1f01685 135.B EDQUOT
9ee4a2b6 136The user's quota of disk blocks or inodes on the filesystem has been
a1f01685
MH
137exhausted.
138.TP
fea681da
MK
139.B EEXIST
140.I pathname
141already exists (not necessarily as a directory).
142This includes the case where
143.I pathname
144is 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
150The final component ("basename") of the new directory's
151.I pathname
152is invalid
153(e.g., it contains characters not permitted by the underlying filesystem).
154.TP
fea681da
MK
155.B ELOOP
156Too many symbolic links were encountered in resolving
157.IR pathname .
158.TP
43537f28
MK
159.B EMLINK
160The 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
167A directory component in
168.I pathname
169does not exist or is a dangling symbolic link.
170.TP
171.B ENOMEM
172Insufficient kernel memory was available.
173.TP
174.B ENOSPC
175The device containing
176.I pathname
177has no room for the new directory.
178.TP
179.B ENOSPC
180The new directory cannot be created because the user's disk quota is
181exhausted.
182.TP
183.B ENOTDIR
184A component used as a directory in
185.I pathname
186is not, in fact, a directory.
187.TP
188.B EPERM
9ee4a2b6 189The filesystem containing
0daa9e92 190.I pathname
fea681da
MK
191does not support the creation of directories.
192.TP
193.B EROFS
194.I pathname
9ee4a2b6 195refers to a file on a read-only filesystem.
bab907ba
MK
196.PP
197The following additional errors can occur for
198.BR mkdirat ():
199.TP
200.B EBADF
201.I dirfd
202is not a valid file descriptor.
203.TP
204.B ENOTDIR
205.I pathname
206is relative and
207.I dirfd
208is a file descriptor referring to a file other than a directory.
209.SH VERSIONS
210.BR mkdirat ()
211was added to Linux in kernel 2.6.16;
212library support was added to glibc in version 2.4.
47297adb 213.SH CONFORMING TO
bab907ba 214.BR mkdir ():
68164150 215SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
97c1eac8 216.\" SVr4 documents additional EIO, EMULTIHOP
efeece04 217.PP
bab907ba
MK
218.BR mkdirat ():
219POSIX.1-2008.
fea681da 220.SH NOTES
5ec64a3a 221Under Linux, apart from the permission bits, the
682edefb 222.B S_ISVTX
5ec64a3a
MK
223.I mode
224bit is also honored.
fea681da 225.PP
c13182ef
MK
226There are many infelicities in the protocol underlying NFS.
227Some of these affect
e511ffb6 228.BR mkdir ().
f17342a5
MK
229.SS Glibc notes
230On older kernels where
231.BR mkdirat ()
232is unavailable, the glibc wrapper function falls back to the use of
233.BR mkdir ().
234When
235.I pathname
236is a relative pathname,
237glibc constructs a pathname based on the symbolic link in
238.IR /proc/self/fd
239that corresponds to the
240.IR dirfd
241argument.
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)