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

Technical Reference: Base Operating System and Extensions, Volume 1

mknod or mkfifo Subroutine


Creates an ordinary file, first-in-first-out (FIFO), or special file.


Standard C Library (libc.a)


#include <sys/stat.h>

int mknod (const char * Path, mode_t Mode, dev_t Device)
char *Path;
int Mode;
dev_t Device;

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


The mknod subroutine creates a new regular file, special file, or FIFO file. Using the mknod subroutine to create file types (other than FIFO or special files) requires root user authority.

For the mknod subroutine to complete successfully, a process must have both search and write permission in the parent directory of the Path parameter.

The mkfifo subroutine is an interface to the mknod subroutine, where the new file to be created is a FIFO or special file. No special system privileges are required.

The new file has the following characteristics:

Upon successful completion, the mkfifo subroutine marks for update the st_atime, st_ctime, and st_mtime fields of the file. It also marks for update the st_ctime and st_mtime fields of the directory that contains the new entry.

If the new file is a character special file having the S_IMPX attribute (multiplexed character special file), when the file is used, additional path-name components can appear after the path name as if it were a directory. The additional part of the path name is available to the device driver of the file for interpretation. This feature provides a multiplexed interface to the device driver.


Path Names the new file. If Network File System (NFS) is installed on your system, this path can cross into another node.
Mode Specifies the file type, attributes, and access permissions. This parameter is constructed by logically ORing values described in the sys/mode.h file.
Device Specifies the ID of the device, which corresponds to the st_rdev member of the structure returned by the statx subroutine. This parameter is configuration-dependent and used only if the Mode parameter specifies a block or character special file. If the file you specify is a remote file, the value of the Device parameter must be meaningful on the node where the file resides.

Return Values

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

Error Codes

The mknod subroutine fails and the new file is not created if one or more of the following are true:

EEXIST The named file exists.
EDQUOT The directory in which the entry for the new file is being placed cannot be extended, or an i-node could not be allocated for the file because the user's or group's quota of disk blocks or i-nodes on the file system is exhausted.
EISDIR The Mode parameter specifies a directory. Use the mkdir subroutine instead.
ENOSPC The directory that would contain the new file cannot be extended, or the file system is out of file-allocation resources.
EPERM The Mode parameter specifies a file type other than S_IFIFO, and the calling process does not have root user authority.
EROFS The directory in which the file is to be created is located on a read-only file system.

The mknod and mkfifo subroutine can be unsuccessful for other reasons. See "Appendix. A Base Operating System Error Codes for Services That Require Path-Name Resolution" (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 mknod subroutine can also fail if the following is true:

ETIMEDOUT The connection timed out.

Implementation Specifics

These subroutines are part of Base Operating System (BOS) Runtime.

Related Information

The chmod (chmod or fchmod Subroutine) subroutine, mkdir (mkdir Subroutine) subroutine, open, openx, or creat (open, openx, open64, creat, or creat64 Subroutine) subroutine, statx subroutine, umask subroutine.

The chmod command, mkdir command, mknod command.

The mode.h file, types.h file.

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

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