1MKNOD(2)                   Linux Programmer's Manual                  MKNOD(2)
2
3
4

NAME

6       mknod - create a special or ordinary file
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/stat.h>
11       #include <fcntl.h>
12       #include <unistd.h>
13
14       int mknod(const char *pathname, mode_t mode, dev_t dev);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       mknod(): _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
19

DESCRIPTION

21       The  system  call mknod() creates a file system node (file, device spe‐
22       cial file or named pipe) named pathname, with attributes  specified  by
23       mode and dev.
24
25       The mode argument specifies both the permissions to use and the type of
26       node to be created.  It should be a combination (using bitwise  OR)  of
27       one  of  the  file  types  listed below and the permissions for the new
28       node.
29
30       The permissions are modified by the process's umask in the  usual  way:
31       the permissions of the created node are (mode & ~umask).
32
33       The  file  type  must  be  one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO or
34       S_IFSOCK to specify a regular file (which will be created empty), char‐
35       acter  special  file,  block  special  file, FIFO (named pipe), or Unix
36       domain socket, respectively.  (Zero file type  is  equivalent  to  type
37       S_IFREG.)
38
39       If the file type is S_IFCHR or S_IFBLK then dev specifies the major and
40       minor numbers of the newly created device special file (makedev(3)  may
41       be useful to build the value for dev); otherwise it is ignored.
42
43       If pathname already exists, or is a symbolic link, this call fails with
44       an EEXIST error.
45
46       The newly created node will be owned by the effective user  ID  of  the
47       process.  If the directory containing the node has the set-group-ID bit
48       set, or if the file system is mounted with BSD group semantics, the new
49       node will inherit the group ownership from its parent directory; other‐
50       wise it will be owned by the effective group ID of the process.
51

RETURN VALUE

53       mknod() returns zero on success, or -1 if an error occurred  (in  which
54       case, errno is set appropriately).
55

ERRORS

57       EACCES The  parent  directory  does  not  allow write permission to the
58              process, or one of the directories in the path prefix  of  path‐
59              name  did  not  allow search permission.  (See also path_resolu‐
60              tion(7).)
61
62       EEXIST pathname already exists.  This includes the case where  pathname
63              is a symbolic link, dangling or not.
64
65       EFAULT pathname points outside your accessible address space.
66
67       EINVAL mode  requested creation of something other than a regular file,
68              device special file, FIFO or socket.
69
70       ELOOP  Too many symbolic links were encountered in resolving pathname.
71
72       ENAMETOOLONG
73              pathname was too long.
74
75       ENOENT A directory component in pathname does not exist or  is  a  dan‐
76              gling symbolic link.
77
78       ENOMEM Insufficient kernel memory was available.
79
80       ENOSPC The device containing pathname has no room for the new node.
81
82       ENOTDIR
83              A  component  used as a directory in pathname is not, in fact, a
84              directory.
85
86       EPERM  mode requested creation of something other than a regular  file,
87              FIFO  (named pipe), or Unix domain socket, and the caller is not
88              privileged (Linux: does not have the CAP_MKNOD capability); also
89              returned if the file system containing pathname does not support
90              the type of node requested.
91
92       EROFS  pathname refers to a file on a read-only file system.
93

CONFORMING TO

95       SVr4, 4.4BSD, POSIX.1-2001 (but see below).
96

NOTES

98       POSIX.1-2001 says: "The only portable use of mknod()  is  to  create  a
99       FIFO-special  file.  If mode is not S_IFIFO or dev is not 0, the behav‐
100       ior of mknod() is unspecified."  However, nowadays one should never use
101       mknod()  for  this  purpose; one should use mkfifo(3), a function espe‐
102       cially defined for this purpose.
103
104       Under Linux, this call cannot  be  used  to  create  directories.   One
105       should make directories with mkdir(2).
106
107       There  are  many  infelicities in the protocol underlying NFS.  Some of
108       these affect mknod().
109

SEE ALSO

111       chmod(2),   chown(2),   fcntl(2),   mkdir(2),   mknodat(2),   mount(2),
112       socket(2),   stat(2),   umask(2),   unlink(2),  makedev(3),  mkfifo(3),
113       path_resolution(7)
114

COLOPHON

116       This page is part of release 3.22 of the Linux  man-pages  project.   A
117       description  of  the project, and information about reporting bugs, can
118       be found at http://www.kernel.org/doc/man-pages/.
119
120
121
122Linux                             2008-12-01                          MKNOD(2)
Impressum