416 lines
8.3 KiB
HTML
416 lines
8.3 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of MKDIR</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>MKDIR</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
mkdir, mkdirat - create a directory
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
|
|
<B>int mkdir(const char *</B><I>pathname</I><B>, mode_t </B><I>mode</I><B>);</B>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>> </B>/* Definition of AT_* constants */
|
|
<B>#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>></B>
|
|
|
|
<B>int mkdirat(int </B><I>dirfd</I><B>, const char *</B><I>pathname</I><B>, mode_t </B><I>mode</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>mkdirat</B>():
|
|
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
<DL COMPACT>
|
|
<DT id="2">Since glibc 2.10:<DD>
|
|
_POSIX_C_SOURCE >= 200809L
|
|
<DT id="3">Before glibc 2.10:<DD>
|
|
_ATFILE_SOURCE
|
|
</DL>
|
|
</DL>
|
|
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>mkdir</B>()
|
|
|
|
attempts to create a directory named
|
|
<I>pathname</I>.
|
|
|
|
<P>
|
|
|
|
The argument
|
|
<I>mode</I>
|
|
|
|
specifies the mode for the new directory (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7)).
|
|
|
|
It is modified by the process's
|
|
<I>umask</I>
|
|
|
|
in the usual way: in the absence of a default ACL, the mode of the
|
|
created directory is
|
|
(<I>mode</I> & ~<I>umask</I> & 0777).
|
|
|
|
Whether other
|
|
<I>mode</I>
|
|
|
|
bits are honored for the created directory depends on the operating system.
|
|
For Linux, see NOTES below.
|
|
<P>
|
|
|
|
The newly created directory will be owned by the effective user ID of the
|
|
process.
|
|
If the directory containing the file has the set-group-ID
|
|
bit set, or if the filesystem is mounted with BSD group semantics
|
|
(<I>mount -o bsdgroups</I>
|
|
|
|
or, synonymously
|
|
<I>mount -o grpid</I>),
|
|
|
|
the new directory will inherit the group ownership from its parent;
|
|
otherwise it will be owned by the effective group ID of the process.
|
|
<P>
|
|
|
|
If the parent directory has the set-group-ID bit set, then so will the
|
|
newly created directory.
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>mkdirat()</H3>
|
|
|
|
The
|
|
<B>mkdirat</B>()
|
|
|
|
system call operates in exactly the same way as
|
|
<B>mkdir</B>(),
|
|
|
|
except for the differences described here.
|
|
<P>
|
|
|
|
If the pathname given in
|
|
<I>pathname</I>
|
|
|
|
is relative, then it is interpreted relative to the directory
|
|
referred to by the file descriptor
|
|
<I>dirfd</I>
|
|
|
|
(rather than relative to the current working directory of
|
|
the calling process, as is done by
|
|
<B>mkdir</B>()
|
|
|
|
for a relative pathname).
|
|
<P>
|
|
|
|
If
|
|
<I>pathname</I>
|
|
|
|
is relative and
|
|
<I>dirfd</I>
|
|
|
|
is the special value
|
|
<B>AT_FDCWD</B>,
|
|
|
|
then
|
|
<I>pathname</I>
|
|
|
|
is interpreted relative to the current working
|
|
directory of the calling process (like
|
|
<B>mkdir</B>()).
|
|
|
|
<P>
|
|
|
|
If
|
|
<I>pathname</I>
|
|
|
|
is absolute, then
|
|
<I>dirfd</I>
|
|
|
|
is ignored.
|
|
<P>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?2+openat">openat</A></B>(2)
|
|
|
|
for an explanation of the need for
|
|
<B>mkdirat</B>().
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
<B>mkdir</B>()
|
|
|
|
and
|
|
<B>mkdirat</B>()
|
|
|
|
return zero on success, or -1 if an error occurred (in which case,
|
|
<I>errno</I>
|
|
|
|
is set appropriately).
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="4"><B>EACCES</B>
|
|
|
|
<DD>
|
|
The parent directory does not allow write permission to the process,
|
|
or one of the directories in
|
|
<I>pathname</I>
|
|
|
|
did not allow search permission.
|
|
(See also
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
|
|
|
|
<DT id="5"><B>EDQUOT</B>
|
|
|
|
<DD>
|
|
The user's quota of disk blocks or inodes on the filesystem has been
|
|
exhausted.
|
|
<DT id="6"><B>EEXIST</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
already exists (not necessarily as a directory).
|
|
This includes the case where
|
|
<I>pathname</I>
|
|
|
|
is a symbolic link, dangling or not.
|
|
<DT id="7"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
<I>pathname</I> points outside your accessible address space.
|
|
|
|
<DT id="8"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The final component ("basename") of the new directory's
|
|
<I>pathname</I>
|
|
|
|
is invalid
|
|
(e.g., it contains characters not permitted by the underlying filesystem).
|
|
<DT id="9"><B>ELOOP</B>
|
|
|
|
<DD>
|
|
Too many symbolic links were encountered in resolving
|
|
<I>pathname</I>.
|
|
|
|
<DT id="10"><B>EMLINK</B>
|
|
|
|
<DD>
|
|
The number of links to the parent directory would exceed
|
|
<B>LINK_MAX</B>.
|
|
|
|
<DT id="11"><B>ENAMETOOLONG</B>
|
|
|
|
<DD>
|
|
<I>pathname</I> was too long.
|
|
|
|
<DT id="12"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
A directory component in
|
|
<I>pathname</I>
|
|
|
|
does not exist or is a dangling symbolic link.
|
|
<DT id="13"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient kernel memory was available.
|
|
<DT id="14"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
The device containing
|
|
<I>pathname</I>
|
|
|
|
has no room for the new directory.
|
|
<DT id="15"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
The new directory cannot be created because the user's disk quota is
|
|
exhausted.
|
|
<DT id="16"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
A component used as a directory in
|
|
<I>pathname</I>
|
|
|
|
is not, in fact, a directory.
|
|
<DT id="17"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The filesystem containing
|
|
<I>pathname</I>
|
|
|
|
does not support the creation of directories.
|
|
<DT id="18"><B>EROFS</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
refers to a file on a read-only filesystem.
|
|
</DL>
|
|
<P>
|
|
|
|
The following additional errors can occur for
|
|
<B>mkdirat</B>():
|
|
|
|
<DL COMPACT>
|
|
<DT id="19"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>dirfd</I>
|
|
|
|
is not a valid file descriptor.
|
|
<DT id="20"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
is relative and
|
|
<I>dirfd</I>
|
|
|
|
is a file descriptor referring to a file other than a directory.
|
|
</DL>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>mkdirat</B>()
|
|
|
|
was added to Linux in kernel 2.6.16;
|
|
library support was added to glibc in version 2.4.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>mkdir</B>():
|
|
|
|
SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
|
|
|
|
<P>
|
|
|
|
<B>mkdirat</B>():
|
|
|
|
POSIX.1-2008.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Under Linux, apart from the permission bits, the
|
|
<B>S_ISVTX</B>
|
|
|
|
<I>mode</I>
|
|
|
|
bit is also honored.
|
|
<P>
|
|
|
|
There are many infelicities in the protocol underlying NFS.
|
|
Some of these affect
|
|
<B>mkdir</B>().
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Glibc notes</H3>
|
|
|
|
On older kernels where
|
|
<B>mkdirat</B>()
|
|
|
|
is unavailable, the glibc wrapper function falls back to the use of
|
|
<B>mkdir</B>().
|
|
|
|
When
|
|
<I>pathname</I>
|
|
|
|
is a relative pathname,
|
|
glibc constructs a pathname based on the symbolic link in
|
|
<I>/proc/self/fd</I>
|
|
|
|
that corresponds to the
|
|
<I>dirfd</I>
|
|
|
|
argument.
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+mkdir">mkdir</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chmod">chmod</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chown">chown</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mknod">mknod</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+rmdir">rmdir</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+umask">umask</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+unlink">unlink</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+acl">acl</A></B>(5)
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="21"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="22"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="23"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="24"><A HREF="#lbAE">mkdirat()</A><DD>
|
|
</DL>
|
|
<DT id="25"><A HREF="#lbAF">RETURN VALUE</A><DD>
|
|
<DT id="26"><A HREF="#lbAG">ERRORS</A><DD>
|
|
<DT id="27"><A HREF="#lbAH">VERSIONS</A><DD>
|
|
<DT id="28"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="29"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="30"><A HREF="#lbAK">Glibc notes</A><DD>
|
|
</DL>
|
|
<DT id="31"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="32"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|