1.\" $NetBSD: mkdir.2,v 1.29 2013/10/15 11:43:21 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.In sys/stat.h 46.In fcntl.h 47.Ft int 48.Fn mkdirat "int fd" "const char *path" "mode_t mode" 49.Sh DESCRIPTION 50The directory 51.Fa path 52is created with the access permissions specified by 53.Fa mode 54and restricted by the 55.Xr umask 2 56of the calling process. 57.Pp 58.Fn mkdirat 59works the same way as 60.Fn mkdir 61except if 62.Fa path 63is relative. 64In that case, it is looked up from a directory whose file 65descriptor was passed as 66.Fa fd . 67Search permission is required this directory. 68.\" (These alternatives await a decision about the semantics of O_SEARCH) 69.\" Search permission is required on this directory 70.\" except if 71.\" .Fa fd 72.\" was opened with the 73.\" .Dv O_SEARCH 74.\" flag. 75.\" - or - 76.\" This file descriptor must have been opened with the 77.\" .Dv O_SEARCH 78.\" flag. 79.Fa fd 80can be set to 81.Dv AT_FDCWD 82in order to specify the current directory. 83.Pp 84The directory's owner ID is set to the process's effective user ID. 85The directory's group ID is set to that of the parent directory in 86which it is created. 87.Sh RETURN VALUES 88.Rv -std mkdir mkdirat 89.Sh ERRORS 90Both 91.Fn mkdir 92and 93.Fn mkdirat 94will fail and no directory will be created if: 95.Bl -tag -width Er 96.It Bq Er EACCES 97Search permission is denied for a component of the path prefix. 98.It Bq Er EDQUOT 99The new directory cannot be created because the user's 100quota of disk blocks on the file system that will 101contain the directory has been exhausted. 102Or, the user's quota of inodes on the file system on 103which the directory is being created has been exhausted. 104.It Bq Er EEXIST 105The named file exists. 106.It Bq Er EFAULT 107.Fa path 108points outside the process's allocated address space. 109.It Bq Er EIO 110An I/O error occurred while making the directory entry or allocating the inode; 111or an I/O error occurred while reading from or writing to the file system. 112.It Bq Er ELOOP 113Too many symbolic links were encountered in translating the pathname. 114.It Bq Er ENAMETOOLONG 115A component of a pathname exceeded 116.Brq Dv NAME_MAX 117characters, or an entire path name exceeded 118.Brq Dv PATH_MAX 119characters. 120.It Bq Er ENOENT 121A component of the path prefix does not exist. 122.It Bq Er ENOSPC 123The new directory cannot be created because there is no space left 124on the file system that will contain the directory. 125Or, there are no free inodes on the file system on which the 126directory is being created. 127.It Bq Er ENOTDIR 128A component of the path prefix is not a directory. 129.It Bq Er EROFS 130The named file resides on a read-only file system. 131.El 132.Pp 133In addition, 134.Fn mkdirat 135will fail if: 136.Bl -tag -width Er 137.It Bq Er EBADF 138.Fa path 139does not specify an absolute path and 140.Fa fd 141is neither 142.Dv AT_FDCWD 143nor a valid file descriptor open for reading or searching. 144.It Bq Er ENOTDIR 145.Fa path 146is not an absolute path and 147.Fa fd 148is a file descriptor associated with a non-directory file. 149.El 150.Sh SEE ALSO 151.Xr chmod 2 , 152.Xr stat 2 , 153.Xr umask 2 154.Sh STANDARDS 155The 156.Fn mkdir 157function conforms to 158.St -p1003.1-90 . 159.Fn mkdirat 160conforms to 161.St -p1003.1-2008 . 162