xref: /openbsd-src/lib/libc/sys/mkdir.2 (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1.\"	$OpenBSD: mkdir.2,v 1.10 2011/07/18 23:04:40 matthew 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: July 18 2011 $
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.Fd #include <sys/types.h>
42.Fd #include <sys/stat.h>
43.Fd #include <fcntl.h>
44.Ft int
45.Fn mkdir "const char *path" "mode_t mode"
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
85A 0 return value indicates success.
86A \-1 return value indicates an error, and an error code is stored in
87.Va errno .
88.Sh ERRORS
89.Fn mkdir
90and
91.Fn mkdirat
92will fail and no directory will be created if:
93.Bl -tag -width Er
94.It Bq Er ENOTDIR
95A component of the path prefix is not a directory.
96.It Bq Er ENAMETOOLONG
97A component of a pathname exceeded
98.Dv {NAME_MAX}
99characters, or an entire path name exceeded
100.Dv {PATH_MAX}
101characters.
102.It Bq Er ENOENT
103A component of the path prefix does not exist.
104.It Bq Er EACCES
105Search permission is denied for a component of the path prefix.
106.It Bq Er ELOOP
107Too many symbolic links were encountered in translating the pathname.
108.It Bq Er EROFS
109The named file resides on a read-only file system.
110.It Bq Er EEXIST
111The named file exists.
112.It Bq Er ENOSPC
113The new directory cannot be created because there is no space left
114on the file system that will contain the directory.
115.It Bq Er ENOSPC
116There are no free inodes on the file system on which the
117directory is being created.
118.It Bq Er EDQUOT
119The new directory cannot be created because the user's
120quota of disk blocks on the file system that will
121contain the directory has been exhausted.
122.It Bq Er EDQUOT
123The user's quota of inodes on the file system on
124which the directory is being created has been exhausted.
125.It Bq Er EIO
126An I/O error occurred while making the directory entry or allocating the inode.
127.It Bq Er EIO
128An I/O error occurred while reading from or writing to the file system.
129.It Bq Er EFAULT
130.Fa path
131points outside the process's allocated address space.
132.El
133.Pp
134Additionally,
135.Fn mkdirat
136will fail if:
137.Bl -tag -width Er
138.It Bq Er EBADF
139The
140.Fa path
141argument does not specify an absolute path and the
142.Fa fd
143argument is neither
144.Dv AT_FDCWD
145nor a valid file descriptor open for reading.
146.El
147.Sh SEE ALSO
148.Xr chmod 2 ,
149.Xr stat 2 ,
150.Xr umask 2
151.Sh STANDARDS
152The
153.Fn mkdir
154and
155.Fn mkdirat
156functions conform to
157.St -p1003.1-2008 .
158.Sh HISTORY
159The
160.Fn mkdirat
161function appeared in
162.Ox 5.0 .
163