2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved.
45 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
46 .\" Copyright 2016 Joyent, Inc.
48 .TH MKDIR 2 "Sep 24, 2016"
50 mkdir, mkdirat \- make a directory
54 #include <sys/types.h>
57 \fBint\fR \fBmkdir\fR(\fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
61 \fBint\fR \fBmkdirat\fR(\fBint\fR \fIfd\fR, \fBconst char *\fR\fIpath\fR, \fBmode_t\fR \fImode\fR);
66 The \fBmkdir()\fR and \fBmkdirat()\fR functions create a new directory named by
67 the path name pointed to by \fIpath\fR. The mode of the new directory is
68 initialized from \fImode\fR (see \fBchmod\fR(2) for values of mode). The
69 protection part of the \fImode\fR argument is modified by the process's file
70 creation mask (see \fBumask\fR(2)).
73 The directory's owner \fBID\fR is set to the process's effective user ID. The
74 directory's group \fBID\fR is set to the process's effective group ID, or if
75 the \fBS_ISGID\fR bit is set in the parent directory, then the group \fBID\fR
76 of the directory is inherited from the parent. The \fBS_ISGID\fR bit of the
77 new directory is inherited from the parent directory.
80 If \fIpath\fR names a symbolic link, \fBmkdir()\fR and \fBmkdirat()\fR fail and
81 set errno to \fBEEXIST\fR.
84 The newly created directory is empty with the exception of entries for itself
85 (\fB\&.\fR) and its parent directory (\fB\&..\fR).
88 The \fBmkdirat()\fR function behaves similarly to \fBmkdir()\fR; however, if
89 \fIpath\fR is a relative path, then the directory represented by \fBfd\fR is
90 used as the starting point for resolving \fIpath\fR. To use the processes
91 current working directory, \fIfd\fR may be set to the value \fBAT_FDCWD\fR.
94 Upon successful completion, \fBmkdir()\fR and \fBmkdirat()\fR mark for update
95 the \fBst_atime\fR, \fBst_ctime\fR and \fBst_mtime\fR fields of the directory.
96 Also, the \fBst_ctime\fR and \fBst_mtime\fR fields of the directory that
97 contains the new entry are marked for update.
100 Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
101 returned, no directory is created, and \fBerrno\fR is set to indicate the
105 The \fBmkdir()\fR and \fBmkdirat()\fR functions will fail if:
112 Either a component of the path prefix denies search permission or write
113 permission is denied on the parent directory of the directory to be created.
122 The directory where the new file entry is being placed cannot be extended
123 because the user's quota of disk blocks on that file system has been exhausted;
124 the new directory cannot be created because the user's quota of disk blocks on
125 that file system has been exhausted; or the user's quota of inodes on the file
126 system where the file is being created has been exhausted.
135 The named file already exists.
144 The \fIpath\fR argument points to an illegal address.
153 An attempt was made to create an extended attribute that is a directory.
162 An I/O error has occurred while accessing the file system.
171 The path argument includes non-UTF8 characters and the file system accepts only
172 file names where all characters are part of the UTF-8 character codeset.
181 Too many symbolic links were encountered in translating \fIpath\fR, or a loop
182 exists in symbolic links encountered during resolution of \fIpath\fR
191 The maximum number of links to the parent directory would be exceeded.
197 \fB\fBENAMETOOLONG\fR\fR
200 The length of the \fIpath\fR argument exceeds \fBPATH_MAX\fR, or the length of
201 a \fIpath\fR component exceeds \fBNAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
211 A component of the path prefix does not exist or is a null pathname.
220 The \fIpath\fR argument points to a remote machine and the link to that machine
230 No free space is available on the device containing the directory.
239 A component of the path prefix is not a directory. For \fBlinkat()\fR, if
240 \fIpath\fR is a relative path and \fIfd\fR refers to a valid file descriptor
241 which is not a directory.
250 The path prefix resides on a read-only file system.
255 The \fBmkdirat()\fR function will fail if:
262 The path \fIpath\fR is a relative path and \fIfd\fR is not a valid open file
263 descriptor or the value \fBAT_FDCWD\fR.
268 The \fBmkdir()\fR function may fail if:
272 \fB\fBENAMETOOLONG\fR\fR
275 As a result of encountering a symbolic link in resolution of the \fIpath\fR
276 argument, the length of the substituted pathname string exceeded
282 \fBExample 1 \fRCreate a directory.
285 The following example demonstrates how to create a directory named
286 \fB/home/cnd/mod1\fR, with read, write, and search permissions for owner and
287 group, and with read and search permissions for others.
292 #include <sys/types.h>
293 #include <sys/stat.h>
296 status = mkdir("/home/cnd/mod1",
297 S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
303 See \fBattributes\fR(5) for descriptions of the following attributes:
311 ATTRIBUTE TYPE ATTRIBUTE VALUE
313 Interface Stability Standard
315 MT-Level Async-Signal-Safe
320 \fBchmod\fR(2), \fBmknod\fR(2), \fBumask\fR(2), \fBmkdirp\fR(3GEN),
321 \fBstat.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5)