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