Seth Woolley's Man Viewer

Manual for mknod - man 2 mknod

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

MKNOD(2)                   Linux Programmer's Manual                  MKNOD(2)

       mknod(1,2) - create a special or ordinary file(1,n)

       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>
       #include <unistd.h>

       int mknod(1,2)(const char *pathname, mode_t mode, dev_t dev);

       The  system  call mknod(1,2) creates a filesystem node (file(1,n), device special
       file(1,n) or named(5,8) pipe(2,8)) named(5,8) pathname, with attributes specified  by  mode
       and dev.

       The mode argument specifies both the permissions to use and the type of
       node to be created.  It should be a combination (using bitwise  OR)  of
       one  of  the  file(1,n)  types  listed below and the permissions for the new

       The permissions are modified by the process's umask in(1,8) the  usual  way:
       the permissions of the created node are (mode & ~umask).

       The  file(1,n)  type  must  be  one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO or
       S_IFSOCK to specify a normal file(1,n) (which will be created empty),  char-
       acter  special  file(1,n),  block  special  file(1,n), FIFO (named(5,8) pipe(2,8)), or Unix
       domain socket(2,7,n), respectively.  (Zero file(1,n) type  is  equivalent  to  type

       If the file(1,n) type is S_IFCHR or S_IFBLK then dev specifies the major and
       minor numbers of the newly created device special file(1,n); otherwise it is

       If pathname already exists, or is a symbolic link(1,2), this call fails with
       an EEXIST error.

       The newly created node will be owned by the effective user  ID  of  the
       process.  If the directory containing the node has the set(7,n,1 builtins) group ID bit
       set(7,n,1 builtins), or if(3,n) the filesystem is mounted with BSD group semantics, the  new
       node will inherit the group ownership from its parent directory; other-
       wise it will be owned by the effective group ID of the process.

       mknod(1,2) returns zero on success, or -1 if(3,n) an  error(8,n)  occurred  (in(1,8)  which
       case, errno is set(7,n,1 builtins) appropriately).

       EACCES The  parent  directory  does  not  allow write(1,2) permission to the
              process, or one of the directories in(1,8) the path prefix  of  path-
              name  did  not  allow search permission.  (See also path_resolu-

       EEXIST pathname already exists.

       EFAULT pathname points outside your accessible address space.

       EINVAL mode requested creation of something other than a  normal  file(1,n),
              device special file(1,n), FIFO or socket.

       ELOOP  Too  many symbolic links were encountered in(1,8) resolving pathname.

              pathname was too long.

       ENOENT A directory component in(1,8) pathname does not exist or  is  a  dan-
              gling symbolic link.

       ENOMEM Insufficient kernel memory was available.

       ENOSPC The device containing pathname has no room for the new node.

              A  component  used as a directory in(1,8) pathname is not, in(1,8) fact, a

       EPERM  mode requested creation of something other than a regular  file(1,n),
              FIFO  (named(5,8) pipe(2,8)), or Unix domain socket(2,7,n), and the caller is not
              privileged (Linux: does not have the CAP_MKNOD capability); also
              returned  if(3,n) the filesystem containing pathname does not support
              the type of node requested.

       EROFS  pathname refers to a file(1,n) on a read-only filesystem.

       SVr4 (but the call requires  privilege  and  is  thus  not  in(1,8)  POSIX),
       4.4BSD.   The  Linux  version(1,3,5)  differs from the SVr4 version(1,3,5) in(1,8) that it
       does not require root permission to create pipes, also in(1,8) that no EMUL-
       TIHOP, ENOLINK, or EINTR error(8,n) is documented.

       POSIX  1003.1-2001 says: "The only portable use of mknod(1,2)() is to create
       a FIFO-special file. If mode is not S_IFIFO or dev is not 0, the behav-
       ior of mknod(1,2)() is unspecified."

       Under  Linux,  this  call  cannot  be  used to create directories.  One
       should make directories with mkdir(1,2), and FIFOs with mkfifo(1,3).

       There are many infelicities in(1,8) the protocol underlying  NFS.   Some  of
       these affect mknod(1,2).

       fcntl(2),  mkdir(1,2)(2),  mount(2,8)(2), path_resolution(2), socket(2,7,n)(2), stat(1,2)(2),
       umask(2), unlink(1,2)(2), mkfifo(1,3)(3)

Linux 2.6.7                       2004-06-23                          MKNOD(2)

References for this manual (incoming links)