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