mknod, mknodat, mkfifo or mkfifoat, Subroutine

Purpose

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

Library

Standard C Library (libc.a)

Syntax

#include <sys/stat.h>

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

int mknodat (int DirFileDescriptor, const char * Path, mode_tMode, dev_tDevice)
int DirFileDescriptor;
char *Path;
int Mode;
dev_t Device;
int mkfifo (const char *Path, mode_t Mode)
const char *Path;
int Mode;
int mkfifoat (int DirFileDescriptor, const char *Path, mode_tMode)
int DirFileDescriptor;
const char *Path;
int Mode;

Description

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

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

The mkfifo and mkfifoat subroutines are interfaces 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.

The mknodat subroutine is equivalent to the mknod subroutine, and the mkfifoat subroutine is equivalent to the mkfifo subroutine if the DirFileDescriptor parameter is AT_FDCWD or Path is an absolute path name. If DirFileDescriptor is a valid file descriptor of an open directory and Path is a relative path name, Path is considered to be relative to the directory that is associated with the DirFileDescriptor parameter instead of the current working directory.

If DirFileDescriptor was opened without the O_SEARCH open flag, the subroutine checks to determine whether directory searches are permitted for that directory by using the current permissions of the directory. If the directory was opened with the O_SEARCH open flag, the subroutine does not perform the check for that directory.

Parameters

Item Description
DirFileDescriptor Specifies the file descriptor of an open directory.
Path Names the new file. If Network File System (NFS) is installed on your system, this path can cross into another node. If DirFileDescriptor is specified and Path is a relative path name, then Path is considered relative to the directory specified by DirFileDescriptor.
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 and mknodat subroutines fail and the new file is not created if one or more of the following are true:

Item Description
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 mknodat and mkfifoat subroutines fail and the new file is not created if one or more of the following are true:

Item Description
EBADF The Path parameter does not specify an absolute path and the DirFileDescriptor parameter is neither AT_FDCWD nor a valid file descriptor.
ENOTDIR The Path parameter does not specify an absolute path and the DirFileDescriptor parameter is neither AT_FDCWD nor a file descriptor associated with a directory.

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

Item Description
ETIMEDOUT The connection timed out.