1mknod(2)                         System Calls                         mknod(2)
2
3
4

NAME

6       mknod - make a directory, a special file, or a regular file
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int mknod(const char *path, mode_t mode, dev_t dev);
12
13

DESCRIPTION

15       The  mknod() function creates a new file named by the path name pointed
16       to by path. The file type and permissions of the new file are  initial‐
17       ized from mode.
18
19
20       The  file  type  is specified in mode by the S_IFMT bits, which must be
21       set to one of the following values:
22
23       S_IFIFO    fifo special
24
25
26       S_IFCHR    character special
27
28
29       S_IFDIR    directory
30
31
32       S_IFBLK    block special
33
34
35       S_IFREG    ordinary file
36
37
38
39       The file access permissions are specified in mode by the 0007777  bits,
40       and  may be constructed by a bitwise OR operation of the following val‐
41       ues:
42
43
44
45
46       S_ISUID       04000       Set user ID on execution.
47       S_ISGID       020#0       Set group ID on execution if # is 7,  5,
48                                 3,  or  1.  Enable mandatory file/record
49                                 locking if # is 6, 4, 2, or 0
50       S_ISVTX       01000       On  directories,   restricted   deletion
51                                 flag;  on  regular  files  on a UFS file
52                                 system, do not cache flag.
53       S_IRWXU       00700       Read, write, execute by owner.
54       S_IRUSR       00400       Read by owner.
55       S_IWUSR       00200       Write by owner.
56       S_IXUSR       00100       Execute  (search  if  a  directory)   by
57                                 owner.
58       S_IRWXG       00070       Read, write, execute by group.
59       S_IRGRP       00040       Read by group.
60       S_IWGRP       00020       Write by group.
61       S_IXGRP       00010       Execute by group.
62       S_IRWXO       00007       Read, write, execute (search) by others.
63       S_IROTH       00004       Read by others.
64       S_IWOTH       00002       Write by others
65       S_IXOTH       00001       Execute by others.
66
67
68
69       The  owner  ID  of  the  file  is  set  to the effective user ID of the
70       process. The group ID of the file is set to the effective group  ID  of
71       the  process.   However, if the S_ISGID bit is set in the parent direc‐
72       tory, then the group ID of the file is inherited from the  parent.   If
73       the  group  ID of the new file does not match the effective group ID or
74       one of the supplementary group IDs, the S_ISGID bit is cleared.
75
76
77       The access permission bits of mode are modified by the  process's  file
78       mode  creation  mask:  all bits set in the process's file mode creation
79       mask are cleared (see umask(2)). If mode indicates a block or character
80       special file, dev is a configuration-dependent specification of a char‐
81       acter or block I/O device. If mode does not indicate a block special or
82       character special device, dev is ignored. See makedev(3C).
83
84
85       If path is a symbolic link, it is not followed.
86

RETURN VALUES

88       Upon  successful  completion,  mknod() returns 0. Otherwise, it returns
89       −1, the new file is not created, and  errno  is  set  to  indicate  the
90       error.
91

ERRORS

93       The mknod() function will fail if:
94
95       EACCES          A  component  of  the path prefix denies search permis‐
96                       sion, or write  permission  is  denied  on  the  parent
97                       directory.
98
99
100       EDQUOT          The  directory where the new file entry is being placed
101                       cannot be extended because the  user's  quota  of  disk
102                       blocks  on  that file system has been exhausted, or the
103                       user's quota of inodes on the  file  system  where  the
104                       file is being created has been exhausted.
105
106
107       EEXIST          The named file exists.
108
109
110       EFAULT          The path argument points to an illegal address.
111
112
113       EINTR           A signal was caught during the execution of the mknod()
114                       function.
115
116
117       EINVAL          An invalid argument exists.
118
119
120       EIO             An I/O error occurred while accessing the file system.
121
122
123       ELOOP           Too many symbolic links were encountered in translating
124                       path.
125
126
127       ENAMETOOLONG    The  length of the path argument exceeds {PATH_MAX}, or
128                       the length of a path component exceeds {NAME_MAX} while
129                       _POSIX_NO_TRUNC is in effect.
130
131
132       ENOENT          A  component  of the path prefix specified by path does
133                       not name an existing directory  or  path  is  an  empty
134                       string.
135
136
137       ENOLINK         The  path  argument  points to a remote machine and the
138                       link to that machine is no longer active.
139
140
141       ENOSPC          The directory that would contain the new file cannot be
142                       extended  or  the file system is out of file allocation
143                       resources.
144
145
146       ENOTDIR         A component of the path prefix is not a directory.
147
148
149       EPERM           Not all privileges are asserted in the effective set of
150                       the calling process.
151
152
153       EROFS           The  directory  in  which  the file is to be created is
154                       located on a read-only file system.
155
156
157
158       The mknod() function may fail if:
159
160       ENAMETOOLONG    Pathname resolution of  a  symbolic  link  produced  an
161                       intermediate result whose length exceeds {PATH_MAX}.
162
163

USAGE

165       Applications  should  use  the  mkdir(2) function to create a directory
166       because appropriate permissions are not required  and  because  mknod()
167       might  not establish directory entries for the directory itself (.) and
168       the parent directory (..). The mknod() function can be invoked only  by
169       a  privileged  user  for  file  types  other  than  FIFO  special.  The
170       mkfifo(3C) function should be used to create FIFOs.
171
172
173       Doors are created using door_create(3C) and can be attached to the file
174       system  using  fattach(3C).  Symbolic  links  can be created using sym‐
175       link(2).  An  endpoint  for  communication   can   be   created   using
176       socket(3SOCKET).
177

ATTRIBUTES

179       See attributes(5) for descriptions of the following attributes:
180
181
182
183
184       ┌─────────────────────────────┬─────────────────────────────┐
185       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
186       ├─────────────────────────────┼─────────────────────────────┤
187       │Interface Stability          │Standard                     │
188       ├─────────────────────────────┼─────────────────────────────┤
189       │MT-Level                     │Async-Signal-Safe            │
190       └─────────────────────────────┴─────────────────────────────┘
191

SEE ALSO

193       chmod(2),  creat(2),  exec(2),  mkdir(2), open(2), stat(2), symlink(2),
194       umask(2),  door_create(3C),   fattach(3C),   makedev(3C),   mkfifo(3C),
195       socket(3SOCKET),  stat.h(3HEAD),  attributes(5),  privileges(5),  stan‐
196       dards(5)
197
198
199
200SunOS 5.11                        19 Feb 2004                         mknod(2)
Impressum