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

DESCRIPTION

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

RETURN VALUE

65       mkdir() and mkdirat() return  zero  on  success,  or  -1  if  an  error
66       occurred (in which case, errno is set appropriately).
67

ERRORS

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

VERSIONS

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

CONFORMING TO

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

NOTES

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

SEE ALSO

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

COLOPHON

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