mkdir(3posix)


NAME

   mkdir, mkdirat --- make a directory relative to directory file descriptor

SYNOPSIS

   #include <sys/stat.h>

   int mkdir(const char *path, mode_t mode);
   int mkdirat(int fd, const char *path, mode_t mode);

DESCRIPTION

   The mkdir() function shall create a new directory with name path.   The
   file  permission  bits  of  the new directory shall be initialized from
   mode.  These file  permission  bits  of  the  mode  argument  shall  be
   modified by the process' file creation mask.

   When  bits  in  mode  other  than the file permission bits are set, the
   meaning of these additional bits is implementation-defined.

   The directory's user ID shall be set to the process' effective user ID.
   The  directory's  group  ID  shall be set to the group ID of the parent
   directory or to the effective group ID of the process.  Implementations
   shall provide a way to initialize the directory's group ID to the group
   ID of the parent directory. Implementations may, but need not,  provide
   an implementation-defined way to initialize the directory's group ID to
   the effective group ID of the calling process.

   The newly created directory shall be an empty directory.

   If path names a symbolic link, mkdir() shall  fail  and  set  errno  to
   [EEXIST].

   Upon successful completion, mkdir() shall mark for update the last data
   access, last data modification, and last file status change  timestamps
   of the directory. Also, the last data modification and last file status
   change timestamps of the directory that contains the new entry shall be
   marked for update.

   The  mkdirat()  function  shall  be  equivalent to the mkdir() function
   except in the case where path specifies a relative path. In  this  case
   the  newly  created  directory  is  created  relative  to the directory
   associated with the file descriptor fd instead of the  current  working
   directory.  If  the  file  descriptor  was opened without O_SEARCH, the
   function shall check whether directory searches are permitted using the
   current permissions of the directory underlying the file descriptor. If
   the file descriptor was opened with O_SEARCH, the  function  shall  not
   perform the check.

   If  mkdirat() is passed the special value AT_FDCWD in the fd parameter,
   the current working directory shall be used and the behavior  shall  be
   identical to a call to mkdir().

RETURN VALUE

   Upon successful completion, these functions shall return 0.  Otherwise,
   these functions shall return 1 and set errno to indicate the error. If
   1 is returned, no directory shall be created.

ERRORS

   These functions shall fail if:

   EACCES Search  permission  is denied on a component of the path prefix,
          or write permission is denied on the  parent  directory  of  the
          directory to be created.

   EEXIST The named file exists.

   ELOOP  A loop exists in symbolic links encountered during resolution of
          the path argument.

   EMLINK The link count of the parent directory would exceed {LINK_MAX}.

   ENAMETOOLONG
          The  length  of  a  component  of  a  pathname  is  longer  than
          {NAME_MAX}.

   ENOENT A  component  of the path prefix specified by path does not name
          an existing directory or path is an empty string.

   ENOSPC The file system does  not  contain  enough  space  to  hold  the
          contents  of the new directory or to extend the parent directory
          of the new directory.

   ENOTDIR
          A component of the path prefix names an existing  file  that  is
          neither a directory nor a symbolic link to a directory.

   EROFS  The parent directory resides on a read-only file system.

   In addition, the mkdirat() function shall fail if:

   EBADF  The  path  argument does not specify an absolute path and the fd
          argument is neither AT_FDCWD nor a valid  file  descriptor  open
          for reading or searching.

   ENOTDIR
          The  path  argument  is  not  an  absolute path and fd is a file
          descriptor associated with a non-directory file.

   These functions may fail if:

   ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
          resolution of the path argument.

   ENAMETOOLONG
          The  length  of  a  pathname  exceeds  {PATH_MAX},  or  pathname
          resolution of a symbolic link produced  an  intermediate  result
          with a length that exceeds {PATH_MAX}.

   The following sections are informative.

EXAMPLES

   Creating a Directory
   The   following   example   shows  how  to  create  a  directory  named
   /home/cnd/mod1, with read/write/search permissions for owner and group,
   and with read/search permissions for others.

       #include <sys/types.h>
       #include <sys/stat.h>

       int status;
       ...
       status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

APPLICATION USAGE

   None.

RATIONALE

   The mkdir() function originated in 4.2 BSD and was added to System V in
   Release 3.0.

   4.3 BSD detects [ENAMETOOLONG].

   The POSIX.11990 standard required that the group ID of a newly created
   directory  be  set  to  the  group ID of its parent directory or to the
   effective group ID of the creating process. FIPS  1512  required  that
   implementations  provide a way to have the group ID be set to the group
   ID of the containing directory, but did  not  prohibit  implementations
   also  supporting a way to set the group ID to the effective group ID of
   the creating process.  Conforming applications should not assume  which
   group ID will be used. If it matters, an application can use chown() to
   set the group ID after the directory is  created,  or  determine  under
   what conditions the implementation will set the desired group ID.

   The  purpose  of  the  mkdirat()  function  is to create a directory in
   directories other than the current working directory  without  exposure
   to  race conditions. Any part of the path of a file could be changed in
   parallel to the call to mkdir(), resulting in unspecified behavior.  By
   opening  a  file  descriptor  for  the  target  directory and using the
   mkdirat()  function  it  can  be  guaranteed  that  the  newly  created
   directory is located relative to the desired directory.

FUTURE DIRECTIONS

   None.

SEE ALSO

   chmod(), mkdtemp(), mknod(), umask()

   The    Base   Definitions   volume   of   POSIX.12008,   <sys_stat.h>,
   <sys_types.h>

COPYRIGHT

   Portions of this text are reprinted and reproduced in  electronic  form
   from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
   -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
   Specifications  Issue  7,  Copyright  (C)  2013  by  the  Institute  of
   Electrical and Electronics Engineers, Inc and The Open Group.  (This is
   POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
   event of any discrepancy between this version 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.unix.org/online.html .

   Any  typographical  or  formatting  errors that appear in this page are
   most likely to have been introduced during the conversion of the source
   files    to   man   page   format.   To   report   such   errors,   see
   https://www.kernel.org/doc/man-pages/reporting_bugs.html .





Opportunity


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.





Free Software


Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.


Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.





Free Books


The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.


Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.





Education


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.


Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.