mknod() - create a regular file, special file, or directory
#include <sys/stat.h>
int mknod(const char *path, mode_t mode, dev_t dev)
The mknod(2) function creates a new file named by the path name 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 |
S_IFDIR | Directory |
S_IFBLK | Block-special |
S_IFREG | Regular |
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 dev argument is a 32-bit integer that identifies the device. It is constructed using the mkdev() macro using the following syntax:
mkdev(major, minor)
The minor argument is the ordinal number of the device, if more than one device of the specified type is present. The major argument specifies the device type, and must be one of the following values:
Device Type | Value | Path |
---|---|---|
tty-type devices | ||
S_DEV_TTY | 1 | /dev/ttyn[00-63] |
S_DEV_CONSOLE | 2 | /dev/console |
S_DEV_CTRL_TTY | 3 | /dev/tty |
S_DEV_PTM | 4 | /dev/ptynn [p0-Ef] |
S_DEV_PTS | 5 | /dev/ttynn [p0-Ef] |
S_DEV_PTMX | 6 | /dev/ptmx |
S_DEV_SERIAL | 7 | /dev/ttynn [00-1f] |
Stream-type devices | ||
S_DEV_TAPE | 17 | /dev/tapen |
S_DEV_PIPE | 18 | User created FIFO |
S_DEV_SOCKET | 19 | User created socket |
S_DEV_XTI | 20 | User created |
Char/block special file types | ||
S_DEV_NULL | 48 | /dev/null |
S_DEV_ZERO | 49 | /dev/zero |
S_DEV_RANDOM | 50 | /dev/random |
S_DEV_FULL | 51 | /dev/full |
In the case of tape drives, a bit (0x100) is set to indicate that the device does not rewind when it is closed and is cleared to indicate that the drive rewinds when closed. To set this bit, use the bitwise-OR operation when calling mkdev(), as shown:
mkdev(S_DEV_TAPE, 0x100 | minor)
The dev argument is used only when S_IFCHR or S_IFBLK is set in mode; otherwise, it should be set to 0.
The user ID of the file is initialized to the effective user ID of the process. The group ID of the file is initialized 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(2) function clears each bit whose corresponding bit in the file mode creation mask of the process is set.
Upon successful completion, mknod(2) 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.
Upon successful completion, mknod(2) returns 0. Otherwise, it returns -1, the new file is not created, and errno is set to indicate the error.
You must be logged on as a member of the Administrators group to call mknod(2), otherwise the utility returns -1 and sets errno to [EPERM].
Interix recognizes the files created by mknod(2) as unique. Superficially identical files created through means other than mknod(1), mknod(2), and makedev(1) (for example, through backup and restore) will not be treated as device files by Interix, and attempts to open devices through such files with fail with the error code ENXIO.
The mknod(2) function will fail if:
The mknod(2) function may fail if:
For portability to implementations conforming to earlier versions of this specification, mkfifo(2) is preferred over this function for making FIFO special files.
Although it is possible to create device special files on a FAT file system, the Interix subsystem honors these files only if they are located in the /dev directory, which will only happen when Windows Services for UNIX is installed on a FAT partition. The open(2) function will generate an ENXIO error if it tries to open a device special file that is on a FAT partition but not in /dev.
makedev(1)
mkfifo(2)