Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.


MKNOD(2)                      System Calls Manual                     MKNOD(2)

NAME
     mknod, mknodat - make a special file node

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #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);

DESCRIPTION
     mknod with S_IFIFO specified in mode and 0 in dev makes a FIFO file.
     This call is respectively a portable alias for mkfifo(2) and mkfifoat(2).

     mknod with S_IFCHR or S_IFBLK in mode makes a device special file.  The
     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 for creating device special files.

RETURN VALUES
     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.

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

     [EACCES]           Search permission is denied for a component of the
                        path prefix.

     [EDQUOT]           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.

     [EEXIST]           The named file exists.

     [EFAULT]           path points outside the process's allocated address
                        space.

     [EINVAL]           The supplied mode or dev is invalid.

     [EIO]              An I/O error occurred while making the directory entry
                        or allocating the inode.

     [ELOOP]            Too many symbolic links were encountered in
                        translating the pathname.

     [ENAMETOOLONG]     A component of a pathname exceeded {NAME_MAX}
                        characters, or an entire path name exceeded {PATH_MAX}
                        characters.

     [ENOENT]           A component of the path prefix does not exist.

     [ENOSPC]           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.

     [ENOTDIR]          A component of the path prefix is not a directory.

     [EOPNOTSUPP]       The kernel has not been configured to support FIFOs.

     [EPERM]            The process's effective user ID is not super-user.

     [EROFS]            The named file resides on a read-only file system.

     In addition, mknodat() will fail if:

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

     [ENOTDIR]          path is not an absolute path and fd is a file
                        descriptor associated with a non-directory file.

SEE ALSO
     chmod(2), mkfifo(2), stat(2), umask(2), makedev(3)

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

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

     The alias mode for mkfifo(2) and mkfifoat(2) first appeared in NetBSD 9.

NetBSD 10.99                     June 20, 2019                    NetBSD 10.99