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

VERSIONS

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

CONFORMING TO

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

NOTES

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

SEE ALSO

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

COLOPHON

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