xref: /openbsd-src/lib/libc/sys/mkdir.2 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\"	$OpenBSD: mkdir.2,v 1.17 2015/09/10 17:55:21 schwarze Exp $
2.\"	$NetBSD: mkdir.2,v 1.8 1995/02/27 12:34:22 cgd Exp $
3.\"
4.\" Copyright (c) 1983, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)mkdir.2	8.2 (Berkeley) 12/11/93
32.\"
33.Dd $Mdocdate: September 10 2015 $
34.Dt MKDIR 2
35.Os
36.Sh NAME
37.Nm mkdir ,
38.Nm mkdirat
39.Nd make a directory file
40.Sh SYNOPSIS
41.In sys/stat.h
42.Ft int
43.Fn mkdir "const char *path" "mode_t mode"
44.In sys/stat.h
45.In fcntl.h
46.Ft int
47.Fn mkdirat "int fd" "const char *path" "mode_t mode"
48.Sh DESCRIPTION
49The directory
50.Fa path
51is created with the access permissions specified by
52.Fa mode
53and restricted by the
54.Xr umask 2
55of the calling process.
56.Pp
57The directory's owner ID is set to the process's effective user ID.
58The directory's group ID is set to that of the parent directory in
59which it is created.
60.Pp
61The
62.Fn mkdirat
63function is equivalent to
64.Fn mkdir
65except that where
66.Fa path
67specifies a relative path,
68the newly created directory is created relative to
69the directory associated with file descriptor
70.Fa fd
71instead of the current working directory.
72.Pp
73If
74.Fn mkdirat
75is passed the special value
76.Dv AT_FDCWD
77(defined in
78.In fcntl.h )
79in the
80.Fa fd
81parameter, the current working directory is used
82and the behavior is identical to a call to
83.Fn mkdir .
84.Sh RETURN VALUES
85.Rv -std
86.Sh ERRORS
87.Fn mkdir
88and
89.Fn mkdirat
90will fail and no directory will be created if:
91.Bl -tag -width Er
92.It Bq Er ENOTDIR
93A component of the path prefix is not a directory.
94.It Bq Er ENAMETOOLONG
95A component of a pathname exceeded
96.Dv NAME_MAX
97characters, or an entire pathname (including the terminating NUL)
98exceeded
99.Dv PATH_MAX
100bytes.
101.It Bq Er ENOENT
102A component of the path prefix does not exist.
103.It Bq Er EACCES
104Search permission is denied for a component of the path prefix.
105.It Bq Er ELOOP
106Too many symbolic links were encountered in translating the pathname.
107.It Bq Er EROFS
108The named file resides on a read-only file system.
109.It Bq Er EEXIST
110The named file exists.
111.It Bq Er ENOSPC
112The new directory cannot be created because there is no space left
113on the file system that will contain the directory.
114.It Bq Er ENOSPC
115There are no free inodes on the file system on which the
116directory is being created.
117.It Bq Er EDQUOT
118The new directory cannot be created because the user's
119quota of disk blocks on the file system that will
120contain the directory has been exhausted.
121.It Bq Er EDQUOT
122The user's quota of inodes on the file system on
123which the directory is being created has been exhausted.
124.It Bq Er EIO
125An I/O error occurred while making the directory entry or allocating the inode.
126.It Bq Er EIO
127An I/O error occurred while reading from or writing to the file system.
128.It Bq Er EFAULT
129.Fa path
130points outside the process's allocated address space.
131.El
132.Pp
133Additionally,
134.Fn mkdirat
135will fail if:
136.Bl -tag -width Er
137.It Bq Er EBADF
138The
139.Fa path
140argument specifies a relative path and the
141.Fa fd
142argument is neither
143.Dv AT_FDCWD
144nor a valid file descriptor.
145.It Bq Er ENOTDIR
146The
147.Fa path
148argument specifies a relative path and the
149.Fa fd
150argument is a valid file descriptor but it does not reference a directory.
151.It Bq Er EACCES
152The
153.Fa path
154argument specifies a relative path but search permission is denied
155for the directory which the
156.Fa fd
157file descriptor references.
158.El
159.Sh SEE ALSO
160.Xr chmod 2 ,
161.Xr stat 2 ,
162.Xr umask 2
163.Sh STANDARDS
164The
165.Fn mkdir
166and
167.Fn mkdirat
168functions conform to
169.St -p1003.1-2008 .
170.Sh HISTORY
171A
172.Fn mkdir
173system call first appeared in
174.At v1 .
175It was renamed to
176.Fn makdir
177in
178.At v2 .
179However, it did not exist from
180.At v4
181to
182.Bx 4.1 ;
183in those releases,
184.Xr mknod 2
185had to be used.
186Since
187.Fn mkdir
188reappeared in
189.Bx 4.1c ,
190it no longer requires superuser privileges and it automatically creates the
191.Sq \&.
192and
193.Sq \&..
194directory entries.
195.Pp
196The
197.Fn mkdirat
198system call has been available since
199.Ox 5.0 .
200