xref: /netbsd-src/lib/libc/sys/mkdir.2 (revision 62f324d0121177eaf2e0384f92fd9ca2a751c795)
1.\"	$NetBSD: mkdir.2,v 1.27 2013/01/13 08:15:02 dholland Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)mkdir.2	8.2 (Berkeley) 12/11/93
31.\"
32.Dd November 18, 2012
33.Dt MKDIR 2
34.Os
35.Sh NAME
36.Nm mkdir ,
37.Nm mkdirat
38.Nd make a directory file
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/stat.h
43.Ft int
44.Fn mkdir "const char *path" "mode_t mode"
45.Ft int
46.Fn mkdirat "int fd" "const char *path" "mode_t mode"
47.Sh DESCRIPTION
48The directory
49.Fa path
50is created with the access permissions specified by
51.Fa mode
52and restricted by the
53.Xr umask 2
54of the calling process.
55.Pp
56.Fn mkdirat
57works the same way as
58.Fn mkdir
59except if
60.Fa path
61is relative.
62In that case, it is looked up from a directory whose file
63descriptor was passed as
64.Fa fd .
65Search permission is required this directory.
66.\"    (These alternatives await a decision about the semantics of O_SEARCH)
67.\" Search permission is required on this directory
68.\" except if
69.\" .Fa fd
70.\" was opened with the
71.\" .Dv O_SEARCH
72.\" flag.
73.\"    - or -
74.\" This file descriptor must have been opened with the
75.\" .Dv O_SEARCH
76.\" flag.
77.Fa fd
78can be set to
79.Dv AT_FDCWD
80in order to specify the current directory.
81.Pp
82The directory's owner ID is set to the process's effective user ID.
83The directory's group ID is set to that of the parent directory in
84which it is created.
85.Sh RETURN VALUES
86A 0 return value indicates success.
87A \-1 return value indicates an error, and an error code is stored in
88.Va errno .
89.Sh ERRORS
90.Fn mkdir
91will fail and no directory will be created if:
92.Bl -tag -width Er
93.It Bq Er EACCES
94Search permission is denied for a component of the path prefix.
95.It Bq Er EDQUOT
96The new directory cannot be created because the user's
97quota of disk blocks on the file system that will
98contain the directory has been exhausted.
99Or, the user's quota of inodes on the file system on
100which the directory is being created has been exhausted.
101.It Bq Er EEXIST
102The named file exists.
103.It Bq Er EFAULT
104.Fa path
105points outside the process's allocated address space.
106.It Bq Er EIO
107An I/O error occurred while making the directory entry or allocating the inode;
108or an I/O error occurred while reading from or writing to the file system.
109.It Bq Er ELOOP
110Too many symbolic links were encountered in translating the pathname.
111.It Bq Er ENAMETOOLONG
112A component of a pathname exceeded
113.Brq Dv NAME_MAX
114characters, or an entire path name exceeded
115.Brq Dv PATH_MAX
116characters.
117.It Bq Er ENOENT
118A component of the path prefix does not exist.
119.It Bq Er ENOSPC
120The new directory cannot be created because there is no space left
121on the file system that will contain the directory.
122Or, there are no free inodes on the file system on which the
123directory is being created.
124.It Bq Er ENOTDIR
125A component of the path prefix is not a directory.
126.It Bq Er EROFS
127The named file resides on a read-only file system.
128.El
129.Sh SEE ALSO
130.Xr chmod 2 ,
131.Xr stat 2 ,
132.Xr umask 2
133.Sh STANDARDS
134The
135.Fn mkdir
136function conforms to
137.St -p1003.1-90 .
138.Fn mkdirat
139conforms to
140.St -p1003.1-2008 .
141