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():
19           _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
20           _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
21

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

100       SVr4, 4.4BSD, POSIX.1-2001 (but see below).
101

NOTES

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

SEE ALSO

116       chmod(2),   chown(2),   fcntl(2),   mkdir(2),   mknodat(2),   mount(2),
117       socket(2),   stat(2),   umask(2),   unlink(2),  makedev(3),  mkfifo(3),
118       path_resolution(7)
119

COLOPHON

121       This page is part of release 3.53 of the Linux  man-pages  project.   A
122       description  of  the project, and information about reporting bugs, can
123       be found at http://www.kernel.org/doc/man-pages/.
124
125
126
127Linux                             2013-01-27                          MKNOD(2)
Impressum