xref: /freebsd/lib/libsys/mkdir.2 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd March 30, 2020
29.Dt MKDIR 2
30.Os
31.Sh NAME
32.Nm mkdir ,
33.Nm mkdirat
34.Nd make a directory file
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In sys/stat.h
39.Ft int
40.Fn mkdir "const char *path" "mode_t mode"
41.Ft int
42.Fn mkdirat "int fd" "const char *path" "mode_t mode"
43.Sh DESCRIPTION
44The directory
45.Fa path
46is created with the access permissions specified by
47.Fa mode
48and restricted by the
49.Xr umask 2
50of the calling process.
51.Pp
52The directory's owner ID is set to the process's effective user ID.
53The directory's group ID is set to that of the parent directory in
54which it is created.
55.Pp
56The
57.Fn mkdirat
58system call is equivalent to
59.Fn mkdir
60except in the case where
61.Fa path
62specifies a relative path.
63In this case the newly created directory is created relative to the
64directory associated with the file descriptor
65.Fa fd
66instead of the current working directory.
67If
68.Fn mkdirat
69is passed the special value
70.Dv AT_FDCWD
71in the
72.Fa fd
73parameter, the current working directory is used and the behavior is
74identical to a call to
75.Fn mkdir .
76.Sh RETURN VALUES
77.Rv -std mkdir
78.Sh ERRORS
79The
80.Fn mkdir
81system call
82will fail and no directory will be created if:
83.Bl -tag -width Er
84.It Bq Er ENOTDIR
85A component of the path prefix is not a directory.
86.It Bq Er ENAMETOOLONG
87A component of a pathname exceeded 255 characters,
88or an entire path name exceeded 1023 characters.
89.It Bq Er ENOENT
90A component of the path prefix does not exist.
91.It Bq Er EACCES
92Search permission is denied for a component of the path prefix,
93or write permission is denied
94on the parent directory of the directory to be created.
95.It Bq Er ELOOP
96Too many symbolic links were encountered in translating the pathname.
97.It Bq Er EPERM
98The parent directory of the directory to be created has its immutable flag set,
99see the
100.Xr chflags 2
101manual page for more information.
102.It Bq Er EROFS
103The named directory would reside on a read-only file system.
104.It Bq Er EMLINK
105The new directory cannot be created because the parent directory contains
106too many subdirectories.
107.It Bq Er EEXIST
108The named file exists.
109.It Bq Er ENOSPC
110The new directory cannot be created because there is no space left
111on the file system that will contain the directory.
112.It Bq Er ENOSPC
113There are no free inodes on the file system on which the
114directory is being created.
115.It Bq Er EDQUOT
116The new directory cannot be created because the user's
117quota of disk blocks on the file system that will
118contain the directory has been exhausted.
119.It Bq Er EDQUOT
120The user's quota of inodes on the file system on
121which the directory is being created has been exhausted.
122.It Bq Er EIO
123An I/O error occurred while making the directory entry or allocating the inode.
124.It Bq Er EIO
125An I/O error occurred while reading from or writing to the file system.
126.It Bq Er EINTEGRITY
127Corrupted data was detected while reading from the file system.
128.It Bq Er EFAULT
129The
130.Fa path
131argument
132points outside the process's allocated address space.
133.El
134.Pp
135In addition to the errors returned by the
136.Fn mkdir ,
137the
138.Fn mkdirat
139may fail if:
140.Bl -tag -width Er
141.It Bq Er EBADF
142The
143.Fa path
144argument does not specify an absolute path and the
145.Fa fd
146argument is neither
147.Dv AT_FDCWD
148nor a valid file descriptor open for searching.
149.It Bq Er ENOTDIR
150The
151.Fa path
152argument is not an absolute path and
153.Fa fd
154is neither
155.Dv AT_FDCWD
156nor a file descriptor associated with a directory.
157.El
158.Sh SEE ALSO
159.Xr chflags 2 ,
160.Xr chmod 2 ,
161.Xr stat 2 ,
162.Xr umask 2
163.Sh STANDARDS
164The
165.Fn mkdir
166system call is expected to conform to
167.St -p1003.1-90 .
168The
169.Fn mkdirat
170system call follows The Open Group Extended API Set 2 specification.
171.Sh HISTORY
172The
173.Fn mkdirat
174system call appeared in
175.Fx 8.0 .
176The
177.Fn mkdir
178system call appeared in
179.At v1 .
180