1mkdir(2) System Calls Manual mkdir(2)
2
3
4
6 mkdir, mkdirat - create a directory
7
9 Standard C library (libc, -lc)
10
12 #include <sys/stat.h>
13
14 int mkdir(const char *pathname, mode_t mode);
15
16 #include <fcntl.h> /* Definition of AT_* constants */
17 #include <sys/stat.h>
18
19 int mkdirat(int dirfd, const char *pathname, mode_t mode);
20
21 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
23 mkdirat():
24 Since glibc 2.10:
25 _POSIX_C_SOURCE >= 200809L
26 Before glibc 2.10:
27 _ATFILE_SOURCE
28
30 mkdir() attempts to create a directory named pathname.
31
32 The argument mode specifies the mode for the new directory (see in‐
33 ode(7)). It is modified by the process's umask in the usual way: in
34 the absence of a default ACL, the mode of the created directory is
35 (mode & ~umask & 0777). Whether other mode bits are honored for the
36 created directory depends on the operating system. For Linux, see
37 NOTES below.
38
39 The newly created directory will be owned by the effective user ID of
40 the process. If the directory containing the file has the set-group-ID
41 bit set, or if the filesystem is mounted with BSD group semantics
42 (mount -o bsdgroups or, synonymously mount -o grpid), the new directory
43 will inherit the group ownership from its parent; otherwise it will be
44 owned by the effective group ID of the process.
45
46 If the parent directory has the set-group-ID bit set, then so will the
47 newly created directory.
48
49 mkdirat()
50 The mkdirat() system call operates in exactly the same way as mkdir(),
51 except for the differences described here.
52
53 If the pathname given in pathname is relative, then it is interpreted
54 relative to the directory referred to by the file descriptor dirfd
55 (rather than relative to the current working directory of the calling
56 process, as is done by mkdir() for a relative pathname).
57
58 If pathname is relative and dirfd is the special value AT_FDCWD, then
59 pathname is interpreted relative to the current working directory of
60 the calling process (like mkdir()).
61
62 If pathname is absolute, then dirfd is ignored.
63
64 See openat(2) for an explanation of the need for mkdirat().
65
67 mkdir() and mkdirat() return zero on success. On error, -1 is returned
68 and errno is set to indicate the error.
69
71 EACCES The parent directory does not allow write permission to the
72 process, or one of the directories in pathname did not allow
73 search permission. (See also path_resolution(7).)
74
75 EBADF (mkdirat()) pathname is relative but dirfd is neither AT_FDCWD
76 nor a valid file descriptor.
77
78 EDQUOT The user's quota of disk blocks or inodes on the filesystem has
79 been exhausted.
80
81 EEXIST pathname already exists (not necessarily as a directory). This
82 includes the case where pathname is a symbolic link, dangling or
83 not.
84
85 EFAULT pathname points outside your accessible address space.
86
87 EINVAL The final component ("basename") of the new directory's pathname
88 is invalid (e.g., it contains characters not permitted by the
89 underlying filesystem).
90
91 ELOOP Too many symbolic links were encountered in resolving pathname.
92
93 EMLINK The number of links to the parent directory would exceed
94 LINK_MAX.
95
96 ENAMETOOLONG
97 pathname was too long.
98
99 ENOENT A directory component in pathname does not exist or is a dan‐
100 gling symbolic link.
101
102 ENOMEM Insufficient kernel memory was available.
103
104 ENOSPC The device containing pathname has no room for the new direc‐
105 tory.
106
107 ENOSPC The new directory cannot be created because the user's disk
108 quota is exhausted.
109
110 ENOTDIR
111 A component used as a directory in pathname is not, in fact, a
112 directory.
113
114 ENOTDIR
115 (mkdirat()) pathname is relative and dirfd is a file descriptor
116 referring to a file other than a directory.
117
118 EPERM The filesystem containing pathname does not support the creation
119 of directories.
120
121 EROFS pathname refers to a file on a read-only filesystem.
122
124 Under Linux, apart from the permission bits, the S_ISVTX mode bit is
125 also honored.
126
127 glibc notes
128 On older kernels where mkdirat() is unavailable, the glibc wrapper
129 function falls back to the use of mkdir(). When pathname is a relative
130 pathname, glibc constructs a pathname based on the symbolic link in
131 /proc/self/fd that corresponds to the dirfd argument.
132
134 POSIX.1-2008.
135
137 mkdir()
138 SVr4, BSD, POSIX.1-2001.
139
140 mkdirat()
141 Linux 2.6.16, glibc 2.4.
142
144 There are many infelicities in the protocol underlying NFS. Some of
145 these affect mkdir().
146
148 mkdir(1), chmod(2), chown(2), mknod(2), mount(2), rmdir(2), stat(2),
149 umask(2), unlink(2), acl(5), path_resolution(7)
150
151
152
153Linux man-pages 6.05 2023-03-30 mkdir(2)