mknod - make a directory, a special or regular file
#include <sys/stat.h> int mknod(const char *path, mode_t mode, dev_t dev);
The mknod() function creates a new file named by the pathname to which the argument path points.The file type for path is OR-ed into the mode argument, and must be selected from one of the following symbolic constants:
Name Description S_IFIFO FIFO-special S_IFCHR Character-special (non-portable) S_IFDIR Directory (non-portable) S_IFBLK Block-special (non-portable) S_IFREG Regular (non-portable) The only portable use of mknod() is to create a FIFO-special file. If mode is not S_IFIFO or dev is not 0, the behaviour of mknod() is unspecified.
The permissions for the new file are OR-ed into the mode argument, and may be selected from any combination of the following symbolic constants:
Name Description S_ISUID Set user ID on execution. S_ISGID Set group ID on execution. S_IRWXU Read, write or execute (search) by owner. S_IRUSR Read by owner. S_IWUSR Write by owner. S_IXUSR Execute (search) by owner. S_IRWXG Read, write or execute (search) by group. S_IRGRP Read by group. S_IWGRP Write by group. S_IXGRP Execute (search) by group. S_IRWXO Read, write or execute (search) by others. S_IROTH Read by others. S_IWOTH Write by others. S_IXOTH Execute (search) by others. S_ISVTX On directories, restricted deletion flag. The user ID of the file is initialised to the effective user ID of the process. The group ID of the file is initialised to either the effective group ID of the process or the group ID of the parent directory.
The owner, group, and other permission bits of mode are modified by the file mode creation mask of the process. The mknod() function clears each bit whose corresponding bit in the file mode creation mask of the process is set.
Upon successful completion, mknod() marks for update the st_atime, st_ctime and st_mtime fields of the file. Also, the st_ctime and st_mtime fields of the directory that contains the new entry are marked for update.
Only a process with appropriate privileges may invoke mknod() for file types other than FIFO-special.
Upon successful completion, mknod() returns 0. Otherwise, it returns -1, the new file is not created, and errno is set to indicate the error.
The mknod() function will fail if:
- [EPERM]
- The invoking process does not have appropriate privileges and the file type is not FIFO-special.
- [ENOTDIR]
- A component of the path prefix is not a directory.
- [ENOENT]
- A component of the path prefix specified by path does not name an existing directory or path is an empty string.
- [EACCES]
- A component of the path prefix denies search permission, or write permission is denied on the parent directory.
- [EROFS]
- The directory in which the file is to be created is located on a read-only file system.
- [EEXIST]
- The named file exists.
- [EIO]
- An I/O error occurred while accessing the file system.
- [EINVAL]
- An invalid argument exists.
- [ENOSPC]
- The directory that would contain the new file cannot be extended or the file system is out of file allocation resources.
- [ELOOP]
- Too many symbolic links were encountered in resolving path.
- [ENAMETOOLONG]
- The length of a pathname exceeds {PATH_MAX}, or pathname component is longer than {NAME_MAX}.
The mknod() function may fail if:
- [ENAMETOOLONG]
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
None.
For portability to implementations conforming to earlier versions of this specification, mkfifo() is preferred over this function for making FIFO special files.
None.
chmod(), creat(), exec, mkdir(), mkfifo(), open(), stat(), umask(), <sys/stat.h>.