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