2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 2016 Joyent, Inc.
4 .\" Copyright 1989 AT&T
5 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH MKDIR 2 "Sep 24, 2016"
15 mkdir, mkdirat \- make a directory
19 #include <sys/types.h>
22 \fBint\fR \fBmkdir\fR(\fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
26 \fBint\fR \fBmkdirat\fR(\fBint\fR \fIfd\fR, \fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
31 The \fBmkdir()\fR and \fBmkdirat()\fR functions create a new directory named by
32 the path name pointed to by \fIpath\fR. The mode of the new directory is
33 initialized from \fImode\fR (see \fBchmod\fR(2) for values of mode). The
34 protection part of the \fImode\fR argument is modified by the process's file
35 creation mask (see \fBumask\fR(2)).
38 The directory's owner \fBID\fR is set to the process's effective user ID. The
39 directory's group \fBID\fR is set to the process's effective group ID, or if
40 the \fBS_ISGID\fR bit is set in the parent directory, then the group \fBID\fR
41 of the directory is inherited from the parent. The \fBS_ISGID\fR bit of the
42 new directory is inherited from the parent directory.
45 If \fIpath\fR names a symbolic link, \fBmkdir()\fR and \fBmkdirat()\fR fail and
46 set errno to \fBEEXIST\fR.
49 The newly created directory is empty with the exception of entries for itself
50 (\fB\&.\fR) and its parent directory (\fB\&..\fR).
53 The \fBmkdirat()\fR function behaves similarly to \fBmkdir()\fR; however, if
54 \fIpath\fR is a relative path, then the directory represented by \fBfd\fR is
55 used as the starting point for resolving \fIpath\fR. To use the processes
56 current working directory, \fIfd\fR may be set to the value \fBAT_FDCWD\fR.
59 Upon successful completion, \fBmkdir()\fR and \fBmkdirat()\fR mark for update
60 the \fBst_atime\fR, \fBst_ctime\fR and \fBst_mtime\fR fields of the directory.
61 Also, the \fBst_ctime\fR and \fBst_mtime\fR fields of the directory that
62 contains the new entry are marked for update.
65 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
66 returned, no directory is created, and \fBerrno\fR is set to indicate the
70 The \fBmkdir()\fR and \fBmkdirat()\fR functions will fail if:
77 Either a component of the path prefix denies search permission or write
78 permission is denied on the parent directory of the directory to be created.
87 The directory where the new file entry is being placed cannot be extended
88 because the user's quota of disk blocks on that file system has been exhausted;
89 the new directory cannot be created because the user's quota of disk blocks on
90 that file system has been exhausted; or the user's quota of inodes on the file
91 system where the file is being created has been exhausted.
100 The named file already exists.
109 The \fIpath\fR argument points to an illegal address.
118 An attempt was made to create an extended attribute that is a directory.
127 An I/O error has occurred while accessing the file system.
136 The path argument includes non-UTF8 characters and the file system accepts only
137 file names where all characters are part of the UTF-8 character codeset.
146 Too many symbolic links were encountered in translating \fIpath\fR, or a loop
147 exists in symbolic links encountered during resolution of \fIpath\fR
156 The maximum number of links to the parent directory would be exceeded.
162 \fB\fBENAMETOOLONG\fR\fR
165 The length of the \fIpath\fR argument exceeds \fBPATH_MAX\fR, or the length of
166 a \fIpath\fR component exceeds \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
176 A component of the path prefix does not exist or is a null pathname.
185 The \fIpath\fR argument points to a remote machine and the link to that machine
195 No free space is available on the device containing the directory.
204 A component of the path prefix is not a directory. For \fBlinkat()\fR, if
205 \fIpath\fR is a relative path and \fIfd\fR refers to a valid file descriptor
206 which is not a directory.
215 The path prefix resides on a read-only file system.
220 The \fBmkdirat()\fR function will fail if:
227 The path \fIpath\fR is a relative path and \fIfd\fR is not a valid open file
228 descriptor or the value \fBAT_FDCWD\fR.
233 The \fBmkdir()\fR function may fail if:
237 \fB\fBENAMETOOLONG\fR\fR
240 As a result of encountering a symbolic link in resolution of the \fIpath\fR
241 argument, the length of the substituted pathname string exceeded
247 \fBExample 1 \fRCreate a directory.
250 The following example demonstrates how to create a directory named
251 \fB/home/cnd/mod1\fR, with read, write, and search permissions for owner and
252 group, and with read and search permissions for others.
257 #include <sys/types.h>
258 #include <sys/stat.h>
261 status = mkdir("/home/cnd/mod1",
262 S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
268 See \fBattributes\fR(5) for descriptions of the following attributes:
276 ATTRIBUTE TYPE ATTRIBUTE VALUE
278 Interface Stability Standard
280 MT-Level Async-Signal-Safe
285 \fBchmod\fR(2), \fBmknod\fR(2), \fBumask\fR(2), \fBmkdirp\fR(3GEN),
286 \fBstat.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5)