Blame man2/mknod.2

Packit 7cfc04
.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
Packit 7cfc04
.\"             and Copyright (C) 1993 Michael Haardt
Packit 7cfc04
.\"             and Copyright (C) 1993,1994 Ian Jackson
Packit 7cfc04
.\"		and Copyright (C) 2006, 2014, Michael Kerrisk
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
Packit 7cfc04
.\" You may distribute it under the terms of the GNU General
Packit 7cfc04
.\" Public License. It comes with NO WARRANTY.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified 1996-08-18 by urs
Packit 7cfc04
.\" Modified 2003-04-23 by Michael Kerrisk
Packit 7cfc04
.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.TH MKNOD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
mknod, mknodat \- create a special or ordinary file
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.B #include <sys/stat.h>
Packit 7cfc04
.B #include <fcntl.h>
Packit 7cfc04
.B #include <unistd.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int mknod(const char *" pathname ", mode_t " mode ", dev_t " dev );
Packit 7cfc04
Packit 7cfc04
.BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
Packit 7cfc04
.B #include <sys/stat.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int mknodat(int " dirfd ", const char *" pathname ", mode_t " mode \
Packit 7cfc04
", dev_t " dev );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.BR mknod ():
Packit 7cfc04
.ad l
Packit 7cfc04
.RS 4
Packit 7cfc04
_XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
.\"    || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
Packit 7cfc04
    || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.ad
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The system call
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
creates a filesystem node (file, device special file, or
Packit 7cfc04
named pipe) named
Packit 7cfc04
.IR pathname ,
Packit 7cfc04
with attributes specified by
Packit 7cfc04
.I mode
Packit 7cfc04
and
Packit 7cfc04
.IR dev .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I mode
Packit 7cfc04
argument specifies both the file mode to use and the type of node
Packit 7cfc04
to be created.
Packit 7cfc04
It should be a combination (using bitwise OR) of one of the file types
Packit 7cfc04
listed below and zero or more of the file mode bits listed in
Packit 7cfc04
.BR inode (7).
Packit 7cfc04
.PP
Packit 7cfc04
The file mode is modified by the process's
Packit 7cfc04
.I umask
Packit 7cfc04
in the usual way: in the absence of a default ACL, the permissions of the
Packit 7cfc04
created node are
Packit 7cfc04
.RI ( mode " & ~" umask ).
Packit 7cfc04
.PP
Packit 7cfc04
The file type must be one of
Packit 7cfc04
.BR S_IFREG ,
Packit 7cfc04
.BR S_IFCHR ,
Packit 7cfc04
.BR S_IFBLK ,
Packit 7cfc04
.BR S_IFIFO ,
Packit 7cfc04
or
Packit 7cfc04
.B S_IFSOCK
Packit 7cfc04
.\" (S_IFSOCK since Linux 1.2.4)
Packit 7cfc04
to specify a regular file (which will be created empty), character
Packit 7cfc04
special file, block special file, FIFO (named pipe), or UNIX domain socket,
Packit 7cfc04
respectively.
Packit 7cfc04
(Zero file type is equivalent to type
Packit 7cfc04
.BR S_IFREG .)
Packit 7cfc04
.PP
Packit 7cfc04
If the file type is
Packit 7cfc04
.B S_IFCHR
Packit 7cfc04
or
Packit 7cfc04
.BR S_IFBLK ,
Packit 7cfc04
then
Packit 7cfc04
.I dev
Packit 7cfc04
specifies the major and minor numbers of the newly created device
Packit 7cfc04
special file
Packit 7cfc04
.RB ( makedev (3)
Packit 7cfc04
may be useful to build the value for
Packit 7cfc04
.IR dev );
Packit 7cfc04
otherwise it is ignored.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
already exists, or is a symbolic link, this call fails with an
Packit 7cfc04
.B EEXIST
Packit 7cfc04
error.
Packit 7cfc04
.PP
Packit 7cfc04
The newly created node will be owned by the effective user ID of the
Packit 7cfc04
process.
Packit 7cfc04
If the directory containing the node has the set-group-ID
Packit 7cfc04
bit set, or if the filesystem is mounted with BSD group semantics, the
Packit 7cfc04
new node will inherit the group ownership from its parent directory;
Packit 7cfc04
otherwise it will be owned by the effective group ID of the process.
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.SS mknodat()
Packit 7cfc04
The
Packit 7cfc04
.BR mknodat ()
Packit 7cfc04
system call operates in exactly the same way as
Packit 7cfc04
.BR mknod (),
Packit 7cfc04
except for the differences described here.
Packit 7cfc04
.PP
Packit 7cfc04
If the pathname given in
Packit 7cfc04
.I pathname
Packit 7cfc04
is relative, then it is interpreted relative to the directory
Packit 7cfc04
referred to by the file descriptor
Packit 7cfc04
.I dirfd
Packit 7cfc04
(rather than relative to the current working directory of
Packit 7cfc04
the calling process, as is done by
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
for a relative pathname).
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
is relative and
Packit 7cfc04
.I dirfd
Packit 7cfc04
is the special value
Packit 7cfc04
.BR AT_FDCWD ,
Packit 7cfc04
then
Packit 7cfc04
.I pathname
Packit 7cfc04
is interpreted relative to the current working
Packit 7cfc04
directory of the calling process (like
Packit 7cfc04
.BR mknod ()).
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
is absolute, then
Packit 7cfc04
.I dirfd
Packit 7cfc04
is ignored.
Packit 7cfc04
.PP
Packit 7cfc04
See
Packit 7cfc04
.BR openat (2)
Packit 7cfc04
for an explanation of the need for
Packit 7cfc04
.BR mknodat ().
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
and
Packit 7cfc04
.BR mknodat ()
Packit 7cfc04
return zero on success, or \-1 if an error occurred (in which case,
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately).
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
The parent directory does not allow write permission to the process,
Packit 7cfc04
or one of the directories in the path prefix of
Packit 7cfc04
.I pathname
Packit 7cfc04
did not allow search permission.
Packit 7cfc04
(See also
Packit 7cfc04
.BR path_resolution (7).)
Packit 7cfc04
.TP
Packit 7cfc04
.B EDQUOT
Packit 7cfc04
The user's quota of disk blocks or inodes on the filesystem has been
Packit 7cfc04
exhausted.
Packit 7cfc04
.TP
Packit 7cfc04
.B EEXIST
Packit 7cfc04
.I pathname
Packit 7cfc04
already exists.
Packit 7cfc04
This includes the case where
Packit 7cfc04
.I pathname
Packit 7cfc04
is a symbolic link, dangling or not.
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
.IR pathname " points outside your accessible address space."
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I mode
Packit 7cfc04
requested creation of something other than a regular file, device
Packit 7cfc04
special file, FIFO or socket.
Packit 7cfc04
.TP
Packit 7cfc04
.B ELOOP
Packit 7cfc04
Too many symbolic links were encountered in resolving
Packit 7cfc04
.IR pathname .
Packit 7cfc04
.TP
Packit 7cfc04
.B ENAMETOOLONG
Packit 7cfc04
.IR pathname " was too long."
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOENT
Packit 7cfc04
A directory component in
Packit 7cfc04
.I pathname
Packit 7cfc04
does not exist or is a dangling symbolic link.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
Insufficient kernel memory was available.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSPC
Packit 7cfc04
The device containing
Packit 7cfc04
.I pathname
Packit 7cfc04
has no room for the new node.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTDIR
Packit 7cfc04
A component used as a directory in
Packit 7cfc04
.I pathname
Packit 7cfc04
is not, in fact, a directory.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
.I mode
Packit 7cfc04
requested creation of something other than a regular file,
Packit 7cfc04
FIFO (named pipe), or UNIX domain socket, and the caller
Packit 7cfc04
is not privileged (Linux: does not have the
Packit 7cfc04
.B CAP_MKNOD
Packit 7cfc04
capability);
Packit 7cfc04
.\" For UNIX domain sockets and regular files, EPERM is returned only in
Packit 7cfc04
.\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
Packit 7cfc04
.\" use mknod() to make these files.
Packit 7cfc04
also returned if the filesystem containing
Packit 7cfc04
.I pathname
Packit 7cfc04
does not support the type of node requested.
Packit 7cfc04
.TP
Packit 7cfc04
.B EROFS
Packit 7cfc04
.I pathname
Packit 7cfc04
refers to a file on a read-only filesystem.
Packit 7cfc04
.PP
Packit 7cfc04
The following additional errors can occur for
Packit 7cfc04
.BR mknodat ():
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.I dirfd
Packit 7cfc04
is not a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTDIR
Packit 7cfc04
.I pathname
Packit 7cfc04
is relative and
Packit 7cfc04
.I dirfd
Packit 7cfc04
is a file descriptor referring to a file other than a directory.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
.BR mknodat ()
Packit 7cfc04
was added to Linux in kernel 2.6.16;
Packit 7cfc04
library support was added to glibc in version 2.4.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR mknod ():
Packit 7cfc04
SVr4, 4.4BSD, POSIX.1-2001 (but see below), POSIX.1-2008.
Packit 7cfc04
.\" The Linux version differs from the SVr4 version in that it
Packit 7cfc04
.\" does not require root permission to create pipes, also in that no
Packit 7cfc04
.\" EMULTIHOP, ENOLINK, or EINTR error is documented.
Packit 7cfc04
.PP
Packit 7cfc04
.BR mknodat ():
Packit 7cfc04
POSIX.1-2008.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
POSIX.1-2001 says: "The only portable use of
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
is to create a FIFO-special file.
Packit 7cfc04
If
Packit 7cfc04
.I mode
Packit 7cfc04
is not
Packit 7cfc04
.B S_IFIFO
Packit 7cfc04
or
Packit 7cfc04
.I dev
Packit 7cfc04
is not 0, the behavior of
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
is unspecified."
Packit 7cfc04
However, nowadays one should never use
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
for this purpose; one should use
Packit 7cfc04
.BR mkfifo (3),
Packit 7cfc04
a function especially defined for this purpose.
Packit 7cfc04
.PP
Packit 7cfc04
Under Linux,
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
cannot be used to create directories.
Packit 7cfc04
One should make directories with
Packit 7cfc04
.BR mkdir (2).
Packit 7cfc04
.\" and one should make UNIX domain sockets with socket(2) and bind(2).
Packit 7cfc04
.PP
Packit 7cfc04
There are many infelicities in the protocol underlying NFS.
Packit 7cfc04
Some of these affect
Packit 7cfc04
.BR mknod ()
Packit 7cfc04
and
Packit 7cfc04
.BR mknodat ().
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR mknod (1),
Packit 7cfc04
.BR chmod (2),
Packit 7cfc04
.BR chown (2),
Packit 7cfc04
.BR fcntl (2),
Packit 7cfc04
.BR mkdir (2),
Packit 7cfc04
.BR mount (2),
Packit 7cfc04
.BR socket (2),
Packit 7cfc04
.BR stat (2),
Packit 7cfc04
.BR umask (2),
Packit 7cfc04
.BR unlink (2),
Packit 7cfc04
.BR makedev (3),
Packit 7cfc04
.BR mkfifo (3),
Packit 7cfc04
.BR acl (5)
Packit 7cfc04
.BR path_resolution (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.