logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

mknod.3p (9731B)


  1. '\" et
  2. .TH MKNOD "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. mknod, mknodat
  12. \(em make directory, special file, or regular file
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/stat.h>
  17. .P
  18. int mknod(const char *\fIpath\fP, mode_t \fImode\fP, dev_t \fIdev\fP);
  19. .P
  20. #include <fcntl.h>
  21. .P
  22. int mknodat(int \fIfd\fP, const char *\fIpath\fP, mode_t \fImode\fP, dev_t \fIdev\fP);
  23. .fi
  24. .SH DESCRIPTION
  25. The
  26. \fImknod\fR()
  27. function shall create a new file named by the pathname to which the
  28. argument
  29. .IR path
  30. points.
  31. .P
  32. The file type for
  33. .IR path
  34. is OR'ed into the
  35. .IR mode
  36. argument, and the application shall select one of the following
  37. symbolic constants:
  38. .TS
  39. tab(!) box center;
  40. cB | cB
  41. lw(1i) | lw(3i).
  42. Name!Description
  43. _
  44. S_IFIFO!FIFO-special
  45. S_IFCHR!Character-special (non-portable)
  46. S_IFDIR!Directory (non-portable)
  47. S_IFBLK!Block-special (non-portable)
  48. S_IFREG!Regular (non-portable)
  49. .TE
  50. .P
  51. The only portable use of
  52. \fImknod\fR()
  53. is to create a FIFO-special file. If
  54. .IR mode
  55. is not S_IFIFO or
  56. .IR dev
  57. is not 0, the behavior of
  58. \fImknod\fR()
  59. is unspecified.
  60. .P
  61. The permissions for the new file are OR'ed into the
  62. .IR mode
  63. argument, and may be selected from any combination of the following
  64. symbolic constants:
  65. .TS
  66. tab(!) box center;
  67. cB | cB
  68. lw(1i) | lw(3i).
  69. Name!Description
  70. _
  71. S_ISUID!Set user ID on execution.
  72. S_ISGID!Set group ID on execution.
  73. S_IRWXU!Read, write, or execute (search) by owner.
  74. S_IRUSR!Read by owner.
  75. S_IWUSR!Write by owner.
  76. S_IXUSR!Execute (search) by owner.
  77. S_IRWXG!Read, write, or execute (search) by group.
  78. S_IRGRP!Read by group.
  79. S_IWGRP!Write by group.
  80. S_IXGRP!Execute (search) by group.
  81. S_IRWXO!Read, write, or execute (search) by others.
  82. S_IROTH!Read by others.
  83. S_IWOTH!Write by others.
  84. S_IXOTH!Execute (search) by others.
  85. S_ISVTX!On directories, restricted deletion flag.
  86. .TE
  87. .P
  88. The user ID of the file shall be initialized to the effective user ID
  89. of the process. The group ID of the file shall be initialized to either
  90. the effective group ID of the process or the group ID of the parent
  91. directory. Implementations shall provide a way to initialize the file's
  92. group ID to the group ID of the parent directory. Implementations may,
  93. but need not, provide an implementation-defined way to initialize the
  94. file's group ID to the effective group ID of the calling process. The
  95. owner, group, and other permission bits of
  96. .IR mode
  97. shall be modified by the file mode creation mask of the process. The
  98. \fImknod\fR()
  99. function shall clear each bit whose corresponding bit in the file mode
  100. creation mask of the process is set.
  101. .P
  102. If
  103. .IR path
  104. names a symbolic link,
  105. \fImknod\fR()
  106. shall fail and set
  107. .IR errno
  108. to
  109. .BR [EEXIST] .
  110. .P
  111. Upon successful completion,
  112. \fImknod\fR()
  113. shall mark for update the last data access, last data modification,
  114. and last file status change timestamps of the file. Also, the last
  115. data modification and last file status change timestamps of the directory
  116. that contains the new entry shall be marked for update.
  117. .P
  118. Only a process with appropriate privileges may invoke
  119. \fImknod\fR()
  120. for file types other than FIFO-special.
  121. .P
  122. The
  123. \fImknodat\fR()
  124. function shall be equivalent to the
  125. \fImknod\fR()
  126. function except in the case where
  127. .IR path
  128. specifies a relative path. In this case the newly created
  129. directory, special file, or regular file is located relative to the
  130. directory associated with the file descriptor
  131. .IR fd
  132. instead of the current working directory. If the access mode of the
  133. open file description associated with the file descriptor is not
  134. O_SEARCH, the function shall check whether directory searches are
  135. permitted using the current permissions of the directory underlying
  136. the file descriptor. If the access mode is O_SEARCH, the function
  137. shall not perform the check.
  138. .P
  139. If
  140. \fImknodat\fR()
  141. is passed the special value AT_FDCWD in the
  142. .IR fd
  143. parameter, the current working directory shall be used and the behavior
  144. shall be identical to a call to
  145. \fImknod\fR().
  146. .SH "RETURN VALUE"
  147. Upon successful completion, these functions shall return 0.
  148. Otherwise, these functions shall return \-1 and set
  149. .IR errno
  150. to indicate the error. If \-1 is returned, the new file shall
  151. not be created.
  152. .SH ERRORS
  153. These functions shall fail if:
  154. .TP
  155. .BR EACCES
  156. A component of the path prefix denies search permission, or write
  157. permission is denied on the parent directory.
  158. .TP
  159. .BR EEXIST
  160. The named file exists.
  161. .TP
  162. .BR EINVAL
  163. An invalid argument exists.
  164. .TP
  165. .BR EIO
  166. An I/O error occurred while accessing the file system.
  167. .TP
  168. .BR ELOOP
  169. A loop exists in symbolic links encountered during resolution of the
  170. .IR path
  171. argument.
  172. .TP
  173. .BR ENAMETOOLONG
  174. .br
  175. The length of a component of a pathname is longer than
  176. {NAME_MAX}.
  177. .TP
  178. .BR ENOENT
  179. A component of the path prefix of
  180. .IR path
  181. does not name an existing file or
  182. .IR path
  183. is an empty string.
  184. .TP
  185. .BR ENOENT " or " ENOTDIR
  186. .br
  187. The
  188. .IR path
  189. argument contains at least one non-\c
  190. <slash>
  191. character and ends with one or more trailing
  192. <slash>
  193. characters. If
  194. .IR path
  195. without the trailing
  196. <slash>
  197. characters would name an existing file, an
  198. .BR [ENOENT]
  199. error shall not occur.
  200. .TP
  201. .BR ENOSPC
  202. The directory that would contain the new file cannot be extended or the
  203. file system is out of file allocation resources.
  204. .TP
  205. .BR ENOTDIR
  206. A component of the path prefix names an existing file that is neither
  207. a directory nor a symbolic link to a directory.
  208. .TP
  209. .BR EPERM
  210. The invoking process does not have appropriate privileges and the
  211. file type is not FIFO-special.
  212. .TP
  213. .BR EROFS
  214. The directory in which the file is to be created is located on a
  215. read-only file system.
  216. .br
  217. .P
  218. The
  219. \fImknodat\fR()
  220. function shall fail if:
  221. .TP
  222. .BR EACCES
  223. The access mode of the open file description associated with
  224. .IR fd
  225. is not O_SEARCH and the permissions of the directory underlying
  226. .IR fd
  227. do not permit directory searches.
  228. .TP
  229. .BR EBADF
  230. The
  231. .IR path
  232. argument does not specify an absolute path and the
  233. .IR fd
  234. argument is neither AT_FDCWD nor a valid file descriptor open
  235. for reading or searching.
  236. .TP
  237. .BR ENOTDIR
  238. The
  239. .IR path
  240. argument is not an absolute path and
  241. .IR fd
  242. is a file descriptor associated with a non-directory file.
  243. .P
  244. These functions may fail if:
  245. .TP
  246. .BR ELOOP
  247. More than
  248. {SYMLOOP_MAX}
  249. symbolic links were encountered during resolution of the
  250. .IR path
  251. argument.
  252. .TP
  253. .BR ENAMETOOLONG
  254. .br
  255. The length of a pathname exceeds
  256. {PATH_MAX},
  257. or pathname resolution of a symbolic link produced an intermediate
  258. result with a length that exceeds
  259. {PATH_MAX}.
  260. .LP
  261. .IR "The following sections are informative."
  262. .SH EXAMPLES
  263. .SS "Creating a FIFO Special File"
  264. .P
  265. The following example shows how to create a FIFO special file named
  266. .BR /home/cnd/mod_done ,
  267. with read/write permissions for owner, and with read permissions for
  268. group and others.
  269. .sp
  270. .RS 4
  271. .nf
  272. #include <sys/types.h>
  273. #include <sys/stat.h>
  274. .P
  275. dev_t dev;
  276. int status;
  277. \&...
  278. status = mknod("/home/cnd/mod_done", S_IFIFO | S_IWUSR |
  279. S_IRUSR | S_IRGRP | S_IROTH, dev);
  280. .fi
  281. .P
  282. .RE
  283. .SH "APPLICATION USAGE"
  284. The
  285. \fImkfifo\fR()
  286. function is preferred over this function for making FIFO special files.
  287. .SH RATIONALE
  288. The POSIX.1\(hy1990 standard required that the group ID of a newly created file be
  289. set to the group ID of its parent directory or to the effective group
  290. ID of the creating process. FIPS 151\(hy2 required that implementations provide
  291. a way to have the group ID be set to the group ID of the containing
  292. directory, but did not prohibit implementations also supporting a way
  293. to set the group ID to the effective group ID of the creating process.
  294. Conforming applications should not assume which group ID will be used. If
  295. it matters, an application can use
  296. \fIchown\fR()
  297. to set the group ID after the file is created, or determine under
  298. what conditions the implementation will set the desired group ID.
  299. .P
  300. The purpose of the
  301. \fImknodat\fR()
  302. function is to create directories, special files, or regular files in
  303. directories other than the current working directory without exposure
  304. to race conditions. Any part of the path of a file could be changed in
  305. parallel to a call to
  306. \fImknod\fR(),
  307. resulting in unspecified behavior. By opening a file descriptor for
  308. the target directory and using the
  309. \fImknodat\fR()
  310. function it can be guaranteed that the newly created directory, special
  311. file, or regular file is located relative to the desired directory.
  312. .SH "FUTURE DIRECTIONS"
  313. None.
  314. .SH "SEE ALSO"
  315. .IR "\fIchmod\fR\^(\|)",
  316. .IR "\fIcreat\fR\^(\|)",
  317. .IR "\fIexec\fR\^",
  318. .IR "\fIfstatat\fR\^(\|)",
  319. .IR "\fImkdir\fR\^(\|)",
  320. .IR "\fImkfifo\fR\^(\|)",
  321. .IR "\fIopen\fR\^(\|)",
  322. .IR "\fIumask\fR\^(\|)"
  323. .P
  324. The Base Definitions volume of POSIX.1\(hy2017,
  325. .IR "\fB<fcntl.h>\fP",
  326. .IR "\fB<sys_stat.h>\fP"
  327. .\"
  328. .SH COPYRIGHT
  329. Portions of this text are reprinted and reproduced in electronic form
  330. from IEEE Std 1003.1-2017, Standard for Information Technology
  331. -- Portable Operating System Interface (POSIX), The Open Group Base
  332. Specifications Issue 7, 2018 Edition,
  333. Copyright (C) 2018 by the Institute of
  334. Electrical and Electronics Engineers, Inc and The Open Group.
  335. In the event of any discrepancy between this version and the original IEEE and
  336. The Open Group Standard, the original IEEE and The Open Group Standard
  337. is the referee document. The original Standard can be obtained online at
  338. http://www.opengroup.org/unix/online.html .
  339. .PP
  340. Any typographical or formatting errors that appear
  341. in this page are most likely
  342. to have been introduced during the conversion of the source files to
  343. man page format. To report such errors, see
  344. https://www.kernel.org/doc/man-pages/reporting_bugs.html .