|
Packit |
7cfc04 |
'\" et
|
|
Packit |
7cfc04 |
.TH MKDIR "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH PROLOG
|
|
Packit |
7cfc04 |
This manual page is part of the POSIX Programmer's Manual.
|
|
Packit |
7cfc04 |
The Linux implementation of this interface may differ (consult
|
|
Packit |
7cfc04 |
the corresponding Linux manual page for details of Linux behavior),
|
|
Packit |
7cfc04 |
or the interface may not be implemented on Linux.
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
mkdir, mkdirat
|
|
Packit |
7cfc04 |
\(em make a directory relative to directory file descriptor
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
#include <sys/stat.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
int mkdir(const char *\fIpath\fP, mode_t \fImode\fP);
|
|
Packit |
7cfc04 |
int mkdirat(int \fIfd\fP, const char *\fIpath\fP, mode_t \fImode\fP);
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fImkdir\fR()
|
|
Packit |
7cfc04 |
function shall create a new directory with name
|
|
Packit |
7cfc04 |
.IR path .
|
|
Packit |
7cfc04 |
The file permission bits of the new directory shall be initialized from
|
|
Packit |
7cfc04 |
.IR mode .
|
|
Packit |
7cfc04 |
These file permission bits of the
|
|
Packit |
7cfc04 |
.IR mode
|
|
Packit |
7cfc04 |
argument shall be modified by the process' file creation mask.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
When bits in
|
|
Packit |
7cfc04 |
.IR mode
|
|
Packit |
7cfc04 |
other than the file permission bits are set, the meaning of these
|
|
Packit |
7cfc04 |
additional bits is implementation-defined.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The directory's user ID shall be set to the process' effective user ID.
|
|
Packit |
7cfc04 |
The directory's group ID shall be set to the group ID of the parent
|
|
Packit |
7cfc04 |
directory or to the effective group ID of the process. Implementations
|
|
Packit |
7cfc04 |
shall provide a way to initialize the directory's group ID to the group
|
|
Packit |
7cfc04 |
ID of the parent directory. Implementations may, but need not, provide
|
|
Packit |
7cfc04 |
an implementation-defined way to initialize the directory's group ID to
|
|
Packit |
7cfc04 |
the effective group ID of the calling process.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The newly created directory shall be an empty directory.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
names a symbolic link,
|
|
Packit |
7cfc04 |
\fImkdir\fR()
|
|
Packit |
7cfc04 |
shall fail and set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to
|
|
Packit |
7cfc04 |
.BR [EEXIST] .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
Upon successful completion,
|
|
Packit |
7cfc04 |
\fImkdir\fR()
|
|
Packit |
7cfc04 |
shall mark for update the last data access, last data modification,
|
|
Packit |
7cfc04 |
and last file status change timestamps of the directory. Also, the last
|
|
Packit |
7cfc04 |
data modification and last file status change timestamps of the directory
|
|
Packit |
7cfc04 |
that contains the new entry shall be marked for update.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fImkdirat\fR()
|
|
Packit |
7cfc04 |
function shall be equivalent to the
|
|
Packit |
7cfc04 |
\fImkdir\fR()
|
|
Packit |
7cfc04 |
function except in the case where
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
specifies a relative path. In this case the newly created directory is
|
|
Packit |
7cfc04 |
created relative to the directory associated with the file descriptor
|
|
Packit |
7cfc04 |
.IR fd
|
|
Packit |
7cfc04 |
instead of the current working directory. If the file descriptor was
|
|
Packit |
7cfc04 |
opened without O_SEARCH, the function shall check whether directory
|
|
Packit |
7cfc04 |
searches are permitted using the current permissions of the directory
|
|
Packit |
7cfc04 |
underlying the file descriptor. If the file descriptor was opened with
|
|
Packit |
7cfc04 |
O_SEARCH, the function shall not perform the check.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
\fImkdirat\fR()
|
|
Packit |
7cfc04 |
is passed the special value AT_FDCWD in the
|
|
Packit |
7cfc04 |
.IR fd
|
|
Packit |
7cfc04 |
parameter, the current working directory shall be used and the behavior
|
|
Packit |
7cfc04 |
shall be identical to a call to
|
|
Packit |
7cfc04 |
\fImkdir\fR().
|
|
Packit |
7cfc04 |
.SH "RETURN VALUE"
|
|
Packit |
7cfc04 |
Upon successful completion, these functions shall return 0.
|
|
Packit |
7cfc04 |
Otherwise, these functions shall return \(mi1 and set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to indicate the error. If \(mi1 is returned, no directory shall be created.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
These functions shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EACCES
|
|
Packit |
7cfc04 |
Search permission is denied on a component of the path prefix, or write
|
|
Packit |
7cfc04 |
permission is denied on the parent directory of the directory to be
|
|
Packit |
7cfc04 |
created.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EEXIST
|
|
Packit |
7cfc04 |
The named file exists.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ELOOP
|
|
Packit |
7cfc04 |
A loop exists in symbolic links encountered during resolution of the
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EMLINK
|
|
Packit |
7cfc04 |
The link count of the parent directory would exceed
|
|
Packit |
7cfc04 |
{LINK_MAX}.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENAMETOOLONG
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The length of a component of a pathname is longer than
|
|
Packit |
7cfc04 |
{NAME_MAX}.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOENT
|
|
Packit |
7cfc04 |
A component of the path prefix specified by
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
does not name an existing directory or
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
is an empty string.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOSPC
|
|
Packit |
7cfc04 |
The file system does not contain enough space to hold the contents of
|
|
Packit |
7cfc04 |
the new directory or to extend the parent directory of the new
|
|
Packit |
7cfc04 |
directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOTDIR
|
|
Packit |
7cfc04 |
A component of the path prefix names an existing file that is neither
|
|
Packit |
7cfc04 |
a directory nor a symbolic link to a directory.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EROFS
|
|
Packit |
7cfc04 |
The parent directory resides on a read-only file system.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
In addition, the
|
|
Packit |
7cfc04 |
\fImkdirat\fR()
|
|
Packit |
7cfc04 |
function shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EBADF
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument does not specify an absolute path and the
|
|
Packit |
7cfc04 |
.IR fd
|
|
Packit |
7cfc04 |
argument is neither AT_FDCWD nor a valid file descriptor open for reading
|
|
Packit |
7cfc04 |
or searching.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOTDIR
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument is not an absolute path and
|
|
Packit |
7cfc04 |
.IR fd
|
|
Packit |
7cfc04 |
is a file descriptor associated with a non-directory file.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
These functions may fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ELOOP
|
|
Packit |
7cfc04 |
More than
|
|
Packit |
7cfc04 |
{SYMLOOP_MAX}
|
|
Packit |
7cfc04 |
symbolic links were encountered during resolution of the
|
|
Packit |
7cfc04 |
.IR path
|
|
Packit |
7cfc04 |
argument.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENAMETOOLONG
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The length of a pathname exceeds
|
|
Packit |
7cfc04 |
{PATH_MAX},
|
|
Packit |
7cfc04 |
or pathname resolution of a symbolic link produced an intermediate
|
|
Packit |
7cfc04 |
result with a length that exceeds
|
|
Packit |
7cfc04 |
{PATH_MAX}.
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.IR "The following sections are informative."
|
|
Packit |
7cfc04 |
.SH EXAMPLES
|
|
Packit |
7cfc04 |
.SS "Creating a Directory"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The following example shows how to create a directory named
|
|
Packit |
7cfc04 |
.BR /home/cnd/mod1 ,
|
|
Packit |
7cfc04 |
with read/write/search permissions for owner and group, and with
|
|
Packit |
7cfc04 |
read/search permissions for others.
|
|
Packit |
7cfc04 |
.sp
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
\fB
|
|
Packit |
7cfc04 |
#include <sys/types.h>
|
|
Packit |
7cfc04 |
#include <sys/stat.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
int status;
|
|
Packit |
7cfc04 |
\&...
|
|
Packit |
7cfc04 |
status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
|
Packit |
7cfc04 |
.fi \fR
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.SH "APPLICATION USAGE"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH RATIONALE
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fImkdir\fR()
|
|
Packit |
7cfc04 |
function originated in 4.2 BSD and was added to System V in Release 3.0.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
4.3 BSD detects
|
|
Packit |
7cfc04 |
.BR [ENAMETOOLONG] .
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The POSIX.1\(hy1990 standard required that the group ID of a newly created directory be
|
|
Packit |
7cfc04 |
set to the group ID of its parent directory or to the effective group
|
|
Packit |
7cfc04 |
ID of the creating process. FIPS 151\(hy2 required that implementations provide
|
|
Packit |
7cfc04 |
a way to have the group ID be set to the group ID of the containing
|
|
Packit |
7cfc04 |
directory, but did not prohibit implementations also supporting a way
|
|
Packit |
7cfc04 |
to set the group ID to the effective group ID of the creating process.
|
|
Packit |
7cfc04 |
Conforming applications should not assume which group ID will be used. If
|
|
Packit |
7cfc04 |
it matters, an application can use
|
|
Packit |
7cfc04 |
\fIchown\fR()
|
|
Packit |
7cfc04 |
to set the group ID after the directory is created, or determine under
|
|
Packit |
7cfc04 |
what conditions the implementation will set the desired group ID.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The purpose of the
|
|
Packit |
7cfc04 |
\fImkdirat\fR()
|
|
Packit |
7cfc04 |
function is to create a directory in directories other than the
|
|
Packit |
7cfc04 |
current working directory without exposure to race conditions. Any part
|
|
Packit |
7cfc04 |
of the path of a file could be changed in parallel to the call to
|
|
Packit |
7cfc04 |
\fImkdir\fR(),
|
|
Packit |
7cfc04 |
resulting in unspecified behavior. By opening a file descriptor for
|
|
Packit |
7cfc04 |
the target directory and using the
|
|
Packit |
7cfc04 |
\fImkdirat\fR()
|
|
Packit |
7cfc04 |
function it can be guaranteed that the newly created directory is
|
|
Packit |
7cfc04 |
located relative to the desired directory.
|
|
Packit |
7cfc04 |
.SH "FUTURE DIRECTIONS"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "SEE ALSO"
|
|
Packit |
7cfc04 |
.IR "\fIchmod\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fImkdtemp\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fImknod\fR\^(\|)",
|
|
Packit |
7cfc04 |
.IR "\fIumask\fR\^(\|)"
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "\fB<sys_stat.h>\fP",
|
|
Packit |
7cfc04 |
.IR "\fB<sys_types.h>\fP"
|
|
Packit |
7cfc04 |
.SH COPYRIGHT
|
|
Packit |
7cfc04 |
Portions of this text are reprinted and reproduced in electronic form
|
|
Packit |
7cfc04 |
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
|
|
Packit |
7cfc04 |
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Packit |
7cfc04 |
Specifications Issue 7, Copyright (C) 2013 by the Institute of
|
|
Packit |
7cfc04 |
Electrical and Electronics Engineers, Inc and The Open Group.
|
|
Packit |
7cfc04 |
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
|
|
Packit |
7cfc04 |
event of any discrepancy between this version and the original IEEE and
|
|
Packit |
7cfc04 |
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
Packit |
7cfc04 |
is the referee document. The original Standard can be obtained online at
|
|
Packit |
7cfc04 |
http://www.unix.org/online.html .
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
Any typographical or formatting errors that appear
|
|
Packit |
7cfc04 |
in this page are most likely
|
|
Packit |
7cfc04 |
to have been introduced during the conversion of the source files to
|
|
Packit |
7cfc04 |
man page format. To report such errors, see
|
|
Packit |
7cfc04 |
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|