[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

mkdir Subroutine

Purpose

Creates a directory.

Library

Standard C Library (libc.a)

Syntax

#include <sys/stat.h>


int mkdir ( Path, Mode)
const char *Path;
mode_t Mode;

Description

The mkdir subroutine creates a new directory.

The new directory has the following:

Parameters

Path Specifies the name of the new directory. If Network File System (NFS) is installed on your system, this path can cross into another node. In this case, the new directory is created at that node.

To execute the mkdir subroutine, a process must have search permission to get to the parent directory of the Path parameter as well as write permission in the parent directory itself.

Mode Specifies the mask for the read, write, and execute flags for owner, group, and others. The Mode parameter specifies directory permissions and attributes. This parameter is constructed by logically ORing values described in the sys/mode.h file.

Return Values

Upon successful completion, the mkdir subroutine returns a value of 0. Otherwise, a value of -1 is returned, and the errno global variable is set to indicate the error.

Error Codes

The mkdir subroutine is unsuccessful and the directory is not created if one or more of the following are true:

EACCES Creating the requested directory requires writing in a directory with a mode that denies write permission.
EEXIST The named file already exists.
EROFS The named file resides on a read-only file system.
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.
EMLINK The link count of the parent directory exceeds the maximum (LINK_MAX) number. (LINK_MAX) is defined in limits.h file.
ENAMETOOLONG The Path parameter or a path component is too long and cannot be truncated.
ENOENT A component of the path prefix does not exist or the Path parameter points to an empty string.
ENOTDIR A component of the path prefix is not a directory.
EDQUOT The directory in which the entry for the new directory is being placed cannot be extended, or an i-node or disk blocks could not be allocated for the new directory because the user's or group's quota of disk blocks or i-nodes on the file system containing the directory is exhausted.

The mkdir subroutine can be unsuccessful for other reasons. See "Appendix A. Base Operating System Error Codes for Services That Require Path-Name Resolution" for a list of additional errors.

If NFS is installed on the system, the mkdir subroutine is also unsuccessful if the following is true:

ETIMEDOUT The connection timed out.

Related Information

The chmod (chmod or fchmod Subroutine) subroutine, mknod (mknod or mkfifo Subroutine) subroutine, rmdir subroutine, umask subroutine.

The chmod command, mkdir command, mknod command.

Files, Directories, and File Systems for Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]