MKDIR(2V)

NAME
mkdir - make a directory file

SYNOPSIS

int mkdir(path, mode)
char *path;
int mode;

SYSTEM V SYNOPSIS

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

int mkdir(path, mode)
char *path;
mode_t mode;

DESCRIPTION

mkdir() creates a new directory file with name path. The mode mask of the new directory is initialized from mode.

The low-order 9 bits of mode (the file access permissions) are modified such that all bits set in the process's file mode creation mask are cleared (see umask(2V)).

The set-GID bit of mode is ignored. The set-GID bit of the new file is inherited from that of the parent directory.

The directory's owner ID is set to the process's effective user ID.

The directory's group ID is set to either:

    •   the effective group ID of the process, if the filesystem was not mounted with the BSD file-creation semantics flag (see mount(2V)) and the set-GID bit of the parent directory is clear, or

    •   the group ID of the directory in which the file is created.

Upon successful completion, mkdir() marks for update the st_atime, st_ctime, and st_mtime fields of the directory (see stat(2V)). The st_ctime and st_mtime fields of the directory's parent directory are also marked for update.

RETURN VALUES

mkdir() returns:

0   on success.

-1  on failure and sets errno to indicate the error.

ERRORS

mkdir() will fail and no directory will be created if:

EACCES
    Search permission is denied for a component of the path prefix of path.

    Write permission is denied on the parent directory of the directory to be created.

EDQUOT
    The directory in which the entry for the new file is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted.

    The new directory cannot be created because the user's quota of disk blocks on the file system which will contain the directory has been exhausted.

    The user's quota of inodes on the file system on which the file is being created has been exhausted.

EEXIST
    The file referred to by path exists.

EFAULT
    path points outside the process's allocated address space.

EIO An I/O error occurred while reading from or writing to the file system.

ELOOP
    Too many symbolic links were encountered in translating path.

EMLINK
    The link count of the parent directory would exceed {LINK_MAX} (see pathconf(2V)).

ENAMETOOLONG
    The length of the path argument exceeds {PATH_MAX}.

    A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf(2V)).

ENOENT
    A component of the path prefix of path does not exist.

ENOSPC
    The directory in which the entry for the new file is being placed cannot be extended because there is no space left on the file system containing the directory.

    The new directory cannot be created because there is no space left on the file system which will contain the directory.

    There are no free inodes on the file system on which the file is being created.

ENOTDIR
    A component of the path prefix of path is not a directory.

EROFS
    path The parent directory of the directory to be created resides on a read-only file system.

SYSTEM V ERRORS

In addition to the above, the following may also occur:

ENOENT
    path points to a null pathname.

SEE ALSO
chmod(2V), mount(2V), rmdir(2V), stat(2V), umask(2V)