1.\" $NetBSD: mkdir.2,v 1.28 2013/07/28 14:38:25 njoly 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 July 28, 2013 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 86.Rv -std mkdir mkdirat 87.Sh ERRORS 88Both 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 EACCES 95Search permission is denied for a component of the path prefix. 96.It Bq Er EDQUOT 97The new directory cannot be created because the user's 98quota of disk blocks on the file system that will 99contain the directory has been exhausted. 100Or, the user's quota of inodes on the file system on 101which the directory is being created has been exhausted. 102.It Bq Er EEXIST 103The named file exists. 104.It Bq Er EFAULT 105.Fa path 106points outside the process's allocated address space. 107.It Bq Er EIO 108An I/O error occurred while making the directory entry or allocating the inode; 109or an I/O error occurred while reading from or writing to the file system. 110.It Bq Er ELOOP 111Too many symbolic links were encountered in translating the pathname. 112.It Bq Er ENAMETOOLONG 113A component of a pathname exceeded 114.Brq Dv NAME_MAX 115characters, or an entire path name exceeded 116.Brq Dv PATH_MAX 117characters. 118.It Bq Er ENOENT 119A component of the path prefix does not exist. 120.It Bq Er ENOSPC 121The new directory cannot be created because there is no space left 122on the file system that will contain the directory. 123Or, there are no free inodes on the file system on which the 124directory is being created. 125.It Bq Er ENOTDIR 126A component of the path prefix is not a directory. 127.It Bq Er EROFS 128The named file resides on a read-only file system. 129.El 130.Pp 131In addition, 132.Fn mkdirat 133will fail if: 134.Bl -tag -width Er 135.It Bq Er EBADF 136.Fa path 137does not specify an absolute path and 138.Fa fd 139is neither 140.Dv AT_FDCWD 141nor a valid file descriptor open for reading or searching. 142.It Bq Er ENOTDIR 143.Fa path 144is not an absolute path and 145.Fa fd 146is a file descriptor associated with a non-directory file. 147.El 148.Sh SEE ALSO 149.Xr chmod 2 , 150.Xr stat 2 , 151.Xr umask 2 152.Sh STANDARDS 153The 154.Fn mkdir 155function conforms to 156.St -p1003.1-90 . 157.Fn mkdirat 158conforms to 159.St -p1003.1-2008 . 160