1MKDIR(2)                   Linux Programmer's Manual                  MKDIR(2)
2
3
4

NAME

6       mkdir, mkdirat - create a directory
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int mkdir(const char *pathname, mode_t mode);
12
13       #include <fcntl.h>           /* Definition of AT_* constants */
14       #include <sys/stat.h>
15
16       int mkdirat(int dirfd, const char *pathname, mode_t mode);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       mkdirat():
21           Since glibc 2.10:
22               _POSIX_C_SOURCE >= 200809L
23           Before glibc 2.10:
24               _ATFILE_SOURCE
25

DESCRIPTION

27       mkdir() attempts to create a directory named pathname.
28
29       The  argument  mode  specifies  the mode for the new directory (see in‐
30       ode(7)).  It is modified by the process's umask in the  usual  way:  in
31       the  absence  of  a  default  ACL, the mode of the created directory is
32       (mode & ~umask & 0777).  Whether other mode bits are  honored  for  the
33       created  directory  depends  on  the  operating system.  For Linux, see
34       NOTES below.
35
36       The newly created directory will be owned by the effective user  ID  of
37       the process.  If the directory containing the file has the set-group-ID
38       bit set, or if the filesystem  is  mounted  with  BSD  group  semantics
39       (mount -o bsdgroups or, synonymously mount -o grpid), the new directory
40       will inherit the group ownership from its parent; otherwise it will  be
41       owned by the effective group ID of the process.
42
43       If  the parent directory has the set-group-ID bit set, then so will the
44       newly created directory.
45
46   mkdirat()
47       The mkdirat() system call operates in exactly the same way as  mkdir(),
48       except for the differences described here.
49
50       If  the  pathname given in pathname is relative, then it is interpreted
51       relative to the directory referred to  by  the  file  descriptor  dirfd
52       (rather  than  relative to the current working directory of the calling
53       process, as is done by mkdir() for a relative pathname).
54
55       If pathname is relative and dirfd is the special value  AT_FDCWD,  then
56       pathname  is  interpreted  relative to the current working directory of
57       the calling process (like mkdir()).
58
59       If pathname is absolute, then dirfd is ignored.
60
61       See openat(2) for an explanation of the need for mkdirat().
62

RETURN VALUE

64       mkdir() and mkdirat() return zero on success.  On error, -1 is returned
65       and errno is set to indicate the error.
66

ERRORS

68       EACCES The  parent  directory  does  not  allow write permission to the
69              process, or one of the directories in  pathname  did  not  allow
70              search permission.  (See also path_resolution(7).)
71
72       EDQUOT The  user's quota of disk blocks or inodes on the filesystem has
73              been exhausted.
74
75       EEXIST pathname already exists (not necessarily as a directory).   This
76              includes the case where pathname is a symbolic link, dangling or
77              not.
78
79       EFAULT pathname points outside your accessible address space.
80
81       EINVAL The final component ("basename") of the new directory's pathname
82              is  invalid  (e.g.,  it contains characters not permitted by the
83              underlying filesystem).
84
85       ELOOP  Too many symbolic links were encountered in resolving pathname.
86
87       EMLINK The number  of  links  to  the  parent  directory  would  exceed
88              LINK_MAX.
89
90       ENAMETOOLONG
91              pathname was too long.
92
93       ENOENT A  directory  component  in pathname does not exist or is a dan‐
94              gling symbolic link.
95
96       ENOMEM Insufficient kernel memory was available.
97
98       ENOSPC The device containing pathname has no room for  the  new  direc‐
99              tory.
100
101       ENOSPC The  new  directory  cannot  be  created because the user's disk
102              quota is exhausted.
103
104       ENOTDIR
105              A component used as a directory in pathname is not, in  fact,  a
106              directory.
107
108       EPERM  The filesystem containing pathname does not support the creation
109              of directories.
110
111       EROFS  pathname refers to a file on a read-only filesystem.
112
113       The following additional errors can occur for mkdirat():
114
115       EBADF  dirfd is not a valid file descriptor.
116
117       ENOTDIR
118              pathname is relative and dirfd is a file descriptor referring to
119              a file other than a directory.
120

VERSIONS

122       mkdirat()  was  added  to  Linux  in kernel 2.6.16; library support was
123       added to glibc in version 2.4.
124

CONFORMING TO

126       mkdir(): SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
127
128       mkdirat(): POSIX.1-2008.
129

NOTES

131       Under Linux, apart from the permission bits, the S_ISVTX  mode  bit  is
132       also honored.
133
134       There  are  many  infelicities in the protocol underlying NFS.  Some of
135       these affect mkdir().
136
137   Glibc notes
138       On older kernels where mkdirat()  is  unavailable,  the  glibc  wrapper
139       function falls back to the use of mkdir().  When pathname is a relative
140       pathname, glibc constructs a pathname based on  the  symbolic  link  in
141       /proc/self/fd that corresponds to the dirfd argument.
142

SEE ALSO

144       mkdir(1),  chmod(2),  chown(2),  mknod(2), mount(2), rmdir(2), stat(2),
145       umask(2), unlink(2), acl(5), path_resolution(7)
146

COLOPHON

148       This page is part of release 5.12 of the Linux  man-pages  project.   A
149       description  of  the project, information about reporting bugs, and the
150       latest    version    of    this    page,    can     be     found     at
151       https://www.kernel.org/doc/man-pages/.
152
153
154
155Linux                             2021-03-22                          MKDIR(2)
Impressum