477 lines
9.6 KiB
HTML
477 lines
9.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of MKNOD</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>MKNOD</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
mknod, mknodat - create a special or ordinary file
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<B>int mknod(const char *</B><I>pathname</I><B>, mode_t </B><I>mode</I><B>, dev_t </B><I>dev</I><B>);</B>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>> </B>/* Definition of AT_* constants */
|
|
<B>#include <<A HREF="file:///usr/include/sys/stat.h">sys/stat.h</A>></B>
|
|
|
|
<B>int mknodat(int </B><I>dirfd</I><B>, const char *</B><I>pathname</I><B>, mode_t </B><I>mode</I><B>, dev_t </B><I>dev</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>mknod</B>():
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_XOPEN_SOURCE >= 500
|
|
|
|
<BR> || /* Since glibc 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The system call
|
|
<B>mknod</B>()
|
|
|
|
creates a filesystem node (file, device special file, or
|
|
named pipe) named
|
|
<I>pathname</I>,
|
|
|
|
with attributes specified by
|
|
<I>mode</I>
|
|
|
|
and
|
|
<I>dev</I>.
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>mode</I>
|
|
|
|
argument specifies both the file mode to use and the type of node
|
|
to be created.
|
|
It should be a combination (using bitwise OR) of one of the file types
|
|
listed below and zero or more of the file mode bits listed in
|
|
<B><A HREF="/cgi-bin/man/man2html?7+inode">inode</A></B>(7).
|
|
|
|
<P>
|
|
|
|
The file mode is modified by the process's
|
|
<I>umask</I>
|
|
|
|
in the usual way: in the absence of a default ACL, the permissions of the
|
|
created node are
|
|
(<I>mode</I> & ~<I>umask</I>).
|
|
|
|
<P>
|
|
|
|
The file type must be one of
|
|
<B>S_IFREG</B>,
|
|
|
|
<B>S_IFCHR</B>,
|
|
|
|
<B>S_IFBLK</B>,
|
|
|
|
<B>S_IFIFO</B>,
|
|
|
|
or
|
|
<B>S_IFSOCK</B>
|
|
|
|
|
|
to specify a regular file (which will be created empty), character
|
|
special file, block special file, FIFO (named pipe), or UNIX domain socket,
|
|
respectively.
|
|
(Zero file type is equivalent to type
|
|
<B>S_IFREG</B>.)
|
|
|
|
<P>
|
|
|
|
If the file type is
|
|
<B>S_IFCHR</B>
|
|
|
|
or
|
|
<B>S_IFBLK</B>,
|
|
|
|
then
|
|
<I>dev</I>
|
|
|
|
specifies the major and minor numbers of the newly created device
|
|
special file
|
|
(<B><A HREF="/cgi-bin/man/man2html?3+makedev">makedev</A></B>(3)
|
|
|
|
may be useful to build the value for
|
|
<I>dev</I>);
|
|
|
|
otherwise it is ignored.
|
|
<P>
|
|
|
|
If
|
|
<I>pathname</I>
|
|
|
|
already exists, or is a symbolic link, this call fails with an
|
|
<B>EEXIST</B>
|
|
|
|
error.
|
|
<P>
|
|
|
|
The newly created node will be owned by the effective user ID of the
|
|
process.
|
|
If the directory containing the node has the set-group-ID
|
|
bit set, or if the filesystem is mounted with BSD group semantics, the
|
|
new node will inherit the group ownership from its parent directory;
|
|
otherwise it will be owned by the effective group ID of the process.
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>mknodat()</H3>
|
|
|
|
The
|
|
<B>mknodat</B>()
|
|
|
|
system call operates in exactly the same way as
|
|
<B>mknod</B>(),
|
|
|
|
except for the differences described here.
|
|
<P>
|
|
|
|
If the pathname given in
|
|
<I>pathname</I>
|
|
|
|
is relative, then it is interpreted relative to the directory
|
|
referred to by the file descriptor
|
|
<I>dirfd</I>
|
|
|
|
(rather than relative to the current working directory of
|
|
the calling process, as is done by
|
|
<B>mknod</B>()
|
|
|
|
for a relative pathname).
|
|
<P>
|
|
|
|
If
|
|
<I>pathname</I>
|
|
|
|
is relative and
|
|
<I>dirfd</I>
|
|
|
|
is the special value
|
|
<B>AT_FDCWD</B>,
|
|
|
|
then
|
|
<I>pathname</I>
|
|
|
|
is interpreted relative to the current working
|
|
directory of the calling process (like
|
|
<B>mknod</B>()).
|
|
|
|
<P>
|
|
|
|
If
|
|
<I>pathname</I>
|
|
|
|
is absolute, then
|
|
<I>dirfd</I>
|
|
|
|
is ignored.
|
|
<P>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?2+openat">openat</A></B>(2)
|
|
|
|
for an explanation of the need for
|
|
<B>mknodat</B>().
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
<B>mknod</B>()
|
|
|
|
and
|
|
<B>mknodat</B>()
|
|
|
|
return zero on success, or -1 if an error occurred (in which case,
|
|
<I>errno</I>
|
|
|
|
is set appropriately).
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>EACCES</B>
|
|
|
|
<DD>
|
|
The parent directory does not allow write permission to the process,
|
|
or one of the directories in the path prefix of
|
|
<I>pathname</I>
|
|
|
|
did not allow search permission.
|
|
(See also
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
|
|
|
|
<DT id="3"><B>EDQUOT</B>
|
|
|
|
<DD>
|
|
The user's quota of disk blocks or inodes on the filesystem has been
|
|
exhausted.
|
|
<DT id="4"><B>EEXIST</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
already exists.
|
|
This includes the case where
|
|
<I>pathname</I>
|
|
|
|
is a symbolic link, dangling or not.
|
|
<DT id="5"><B>EFAULT</B>
|
|
|
|
<DD>
|
|
<I>pathname</I> points outside your accessible address space.
|
|
|
|
<DT id="6"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>mode</I>
|
|
|
|
requested creation of something other than a regular file, device
|
|
special file, FIFO or socket.
|
|
<DT id="7"><B>ELOOP</B>
|
|
|
|
<DD>
|
|
Too many symbolic links were encountered in resolving
|
|
<I>pathname</I>.
|
|
|
|
<DT id="8"><B>ENAMETOOLONG</B>
|
|
|
|
<DD>
|
|
<I>pathname</I> was too long.
|
|
|
|
<DT id="9"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
A directory component in
|
|
<I>pathname</I>
|
|
|
|
does not exist or is a dangling symbolic link.
|
|
<DT id="10"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient kernel memory was available.
|
|
<DT id="11"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
The device containing
|
|
<I>pathname</I>
|
|
|
|
has no room for the new node.
|
|
<DT id="12"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
A component used as a directory in
|
|
<I>pathname</I>
|
|
|
|
is not, in fact, a directory.
|
|
<DT id="13"><B>EPERM</B>
|
|
|
|
<DD>
|
|
<I>mode</I>
|
|
|
|
requested creation of something other than a regular file,
|
|
FIFO (named pipe), or UNIX domain socket, and the caller
|
|
is not privileged (Linux: does not have the
|
|
<B>CAP_MKNOD</B>
|
|
|
|
capability);
|
|
|
|
|
|
|
|
also returned if the filesystem containing
|
|
<I>pathname</I>
|
|
|
|
does not support the type of node requested.
|
|
<DT id="14"><B>EROFS</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
refers to a file on a read-only filesystem.
|
|
</DL>
|
|
<P>
|
|
|
|
The following additional errors can occur for
|
|
<B>mknodat</B>():
|
|
|
|
<DL COMPACT>
|
|
<DT id="15"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>dirfd</I>
|
|
|
|
is not a valid file descriptor.
|
|
<DT id="16"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
<I>pathname</I>
|
|
|
|
is relative and
|
|
<I>dirfd</I>
|
|
|
|
is a file descriptor referring to a file other than a directory.
|
|
</DL>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>mknodat</B>()
|
|
|
|
was added to Linux in kernel 2.6.16;
|
|
library support was added to glibc in version 2.4.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>mknod</B>():
|
|
|
|
SVr4, 4.4BSD, POSIX.1-2001 (but see below), POSIX.1-2008.
|
|
|
|
|
|
|
|
<P>
|
|
|
|
<B>mknodat</B>():
|
|
|
|
POSIX.1-2008.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
POSIX.1-2001 says: "The only portable use of
|
|
<B>mknod</B>()
|
|
|
|
is to create a FIFO-special file.
|
|
If
|
|
<I>mode</I>
|
|
|
|
is not
|
|
<B>S_IFIFO</B>
|
|
|
|
or
|
|
<I>dev</I>
|
|
|
|
is not 0, the behavior of
|
|
<B>mknod</B>()
|
|
|
|
is unspecified."
|
|
However, nowadays one should never use
|
|
<B>mknod</B>()
|
|
|
|
for this purpose; one should use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkfifo">mkfifo</A></B>(3),
|
|
|
|
a function especially defined for this purpose.
|
|
<P>
|
|
|
|
Under Linux,
|
|
<B>mknod</B>()
|
|
|
|
cannot be used to create directories.
|
|
One should make directories with
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mkdir">mkdir</A></B>(2).
|
|
|
|
|
|
<P>
|
|
|
|
There are many infelicities in the protocol underlying NFS.
|
|
Some of these affect
|
|
<B>mknod</B>()
|
|
|
|
and
|
|
<B>mknodat</B>().
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+mknod">mknod</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chmod">chmod</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chown">chown</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fcntl">fcntl</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mkdir">mkdir</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+mount">mount</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+socket">socket</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+stat">stat</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+umask">umask</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+unlink">unlink</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+makedev">makedev</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+mkfifo">mkfifo</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+acl">acl</A></B>(5)
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="17"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="18"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="19"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="20"><A HREF="#lbAE">mknodat()</A><DD>
|
|
</DL>
|
|
<DT id="21"><A HREF="#lbAF">RETURN VALUE</A><DD>
|
|
<DT id="22"><A HREF="#lbAG">ERRORS</A><DD>
|
|
<DT id="23"><A HREF="#lbAH">VERSIONS</A><DD>
|
|
<DT id="24"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="25"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DT id="26"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="27"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|