OpenBSD manual page server

Manual Page Search Parameters

MKNOD(2) System Calls Manual MKNOD(2)

mknod, mknodatmake a special file node

library “libc”

#include <sys/stat.h>

int
mknod(const char *path, mode_t mode, dev_t dev);

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

int
mknodat(int fd, const char *path, mode_t mode, dev_t dev);

The device special file path is created with the major and minor device numbers specified by dev. The access permissions of path are extracted from mode, modified by the umask(2) of the parent process.

mknodat() works the same way as mknod() except if path is relative. In that case, it is looked up from a directory whose file descriptor was passed as fd. Search permission is required on this directory. fd can be set to AT_FDCWD in order to specify the current directory.

mknod() requires super-user privileges.

The mknod() and mknodat() functions return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

mknod() and mknodat() will fail and the file will be not created if:

[]
Search permission is denied for a component of the path prefix.
[]
The directory in which the entry for the new node is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted; or the user's quota of inodes on the file system on which the node is being created has been exhausted.
[]
The named file exists.
[]
path points outside the process's allocated address space.
[]
The supplied mode or dev is invalid.
[]
An I/O error occurred while making the directory entry or allocating the inode.
[]
Too many symbolic links were encountered in translating the pathname.
[]
A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
[]
A component of the path prefix does not exist.
[]
The directory in which the entry for the new node is being placed cannot be extended because there is no space left on the file system containing the directory; or there are no free inodes on the file system on which the node is being created.
[]
A component of the path prefix is not a directory.
[]
The process's effective user ID is not super-user.
[]
The named file resides on a read-only file system.

In addition, mknodat() will fail if:

[]
path does not specify an absolute path and fd is neither AT_FDCWD nor a valid file descriptor open for reading or searching.
[]
path is not an absolute path and fd is a file descriptor associated with a non-directory file.

chmod(2), mkfifo(2), stat(2), umask(2)

The mknod() function conforms to IEEE Std 1003.1-1990 (“POSIX.1”). mknodat() conforms to IEEE Std 1003.1-2008 (“POSIX.1”).

A mknod() function call appeared in Version 6 AT&T UNIX.

July 29, 2013 NetBSD-7.0.1