1.\" $OpenBSD: mkdir.2,v 1.18 2017/03/23 18:40:01 millert 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: March 23 2017 $ 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, 105or write permission is denied 106on the parent directory of the directory to be created. 107.It Bq Er ELOOP 108Too many symbolic links were encountered in translating the pathname. 109.It Bq Er EROFS 110The named file resides on a read-only file system. 111.It Bq Er EEXIST 112The named file exists. 113.It Bq Er ENOSPC 114The new directory cannot be created because there is no space left 115on the file system that will contain the directory. 116.It Bq Er ENOSPC 117There are no free inodes on the file system on which the 118directory is being created. 119.It Bq Er EDQUOT 120The new directory cannot be created because the user's 121quota of disk blocks on the file system that will 122contain the directory has been exhausted. 123.It Bq Er EDQUOT 124The user's quota of inodes on the file system on 125which the directory is being created has been exhausted. 126.It Bq Er EIO 127An I/O error occurred while making the directory entry or allocating the inode. 128.It Bq Er EIO 129An I/O error occurred while reading from or writing to the file system. 130.It Bq Er EFAULT 131.Fa path 132points outside the process's allocated address space. 133.El 134.Pp 135Additionally, 136.Fn mkdirat 137will fail if: 138.Bl -tag -width Er 139.It Bq Er EBADF 140The 141.Fa path 142argument specifies a relative path and the 143.Fa fd 144argument is neither 145.Dv AT_FDCWD 146nor a valid file descriptor. 147.It Bq Er ENOTDIR 148The 149.Fa path 150argument specifies a relative path and the 151.Fa fd 152argument is a valid file descriptor but it does not reference a directory. 153.It Bq Er EACCES 154The 155.Fa path 156argument specifies a relative path but search permission is denied 157for the directory which the 158.Fa fd 159file descriptor references. 160.El 161.Sh SEE ALSO 162.Xr chmod 2 , 163.Xr stat 2 , 164.Xr umask 2 165.Sh STANDARDS 166The 167.Fn mkdir 168and 169.Fn mkdirat 170functions conform to 171.St -p1003.1-2008 . 172.Sh HISTORY 173A 174.Fn mkdir 175system call first appeared in 176.At v1 . 177It was renamed to 178.Fn makdir 179in 180.At v2 . 181However, it did not exist from 182.At v4 183to 184.Bx 4.1 ; 185in those releases, 186.Xr mknod 2 187had to be used. 188Since 189.Fn mkdir 190reappeared in 191.Bx 4.1c , 192it no longer requires superuser privileges and it automatically creates the 193.Sq \&. 194and 195.Sq \&.. 196directory entries. 197.Pp 198The 199.Fn mkdirat 200system call has been available since 201.Ox 5.0 . 202