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

mkdir.3p (7840B)


  1. '\" et
  2. .TH MKDIR "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. mkdir, mkdirat
  12. \(em make a directory
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/stat.h>
  17. .P
  18. int mkdir(const char *\fIpath\fP, mode_t \fImode\fP);
  19. .P
  20. #include <fcntl.h>
  21. .P
  22. int mkdirat(int \fIfd\fP, const char *\fIpath\fP, mode_t \fImode\fP);
  23. .fi
  24. .SH DESCRIPTION
  25. The
  26. \fImkdir\fR()
  27. function shall create a new directory with name
  28. .IR path .
  29. The file permission bits of the new directory shall be initialized from
  30. .IR mode .
  31. These file permission bits of the
  32. .IR mode
  33. argument shall be modified by the process' file creation mask.
  34. .P
  35. When bits in
  36. .IR mode
  37. other than the file permission bits are set, the meaning of these
  38. additional bits is implementation-defined.
  39. .P
  40. The directory's user ID shall be set to the process' effective user ID.
  41. The directory's group ID shall be set to the group ID of the parent
  42. directory or to the effective group ID of the process. Implementations
  43. shall provide a way to initialize the directory's group ID to the group
  44. ID of the parent directory. Implementations may, but need not, provide
  45. an implementation-defined way to initialize the directory's group ID to
  46. the effective group ID of the calling process.
  47. .P
  48. The newly created directory shall be an empty directory.
  49. .P
  50. If
  51. .IR path
  52. names a symbolic link,
  53. \fImkdir\fR()
  54. shall fail and set
  55. .IR errno
  56. to
  57. .BR [EEXIST] .
  58. .P
  59. Upon successful completion,
  60. \fImkdir\fR()
  61. shall mark for update the last data access, last data modification,
  62. and last file status change timestamps of the directory. Also, the last
  63. data modification and last file status change timestamps of the directory
  64. that contains the new entry shall be marked for update.
  65. .P
  66. The
  67. \fImkdirat\fR()
  68. function shall be equivalent to the
  69. \fImkdir\fR()
  70. function except in the case where
  71. .IR path
  72. specifies a relative path. In this case the newly created directory is
  73. created relative to the directory associated with the file descriptor
  74. .IR fd
  75. instead of the current working directory. If the access mode of the
  76. open file description associated with the file descriptor is not
  77. O_SEARCH, the function shall check whether directory searches are
  78. permitted using the current permissions of the directory underlying
  79. the file descriptor. If the access mode is O_SEARCH, the function
  80. shall not perform the check.
  81. .P
  82. If
  83. \fImkdirat\fR()
  84. is passed the special value AT_FDCWD in the
  85. .IR fd
  86. parameter, the current working directory shall be used and the behavior
  87. shall be identical to a call to
  88. \fImkdir\fR().
  89. .SH "RETURN VALUE"
  90. Upon successful completion, these functions shall return 0.
  91. Otherwise, these functions shall return \-1 and set
  92. .IR errno
  93. to indicate the error. If \-1 is returned, no directory shall be created.
  94. .SH ERRORS
  95. These functions shall fail if:
  96. .TP
  97. .BR EACCES
  98. Search permission is denied on a component of the path prefix, or write
  99. permission is denied on the parent directory of the directory to be
  100. created.
  101. .TP
  102. .BR EEXIST
  103. The named file exists.
  104. .TP
  105. .BR ELOOP
  106. A loop exists in symbolic links encountered during resolution of the
  107. .IR path
  108. argument.
  109. .TP
  110. .BR EMLINK
  111. The link count of the parent directory would exceed
  112. {LINK_MAX}.
  113. .TP
  114. .BR ENAMETOOLONG
  115. .br
  116. The length of a component of a pathname is longer than
  117. {NAME_MAX}.
  118. .TP
  119. .BR ENOENT
  120. A component of the path prefix specified by
  121. .IR path
  122. does not name an existing directory or
  123. .IR path
  124. is an empty string.
  125. .TP
  126. .BR ENOSPC
  127. The file system does not contain enough space to hold the contents of
  128. the new directory or to extend the parent directory of the new
  129. directory.
  130. .TP
  131. .BR ENOTDIR
  132. A component of the path prefix names an existing file that is neither
  133. a directory nor a symbolic link to a directory.
  134. .TP
  135. .BR EROFS
  136. The parent directory resides on a read-only file system.
  137. .P
  138. In addition, the
  139. \fImkdirat\fR()
  140. function shall fail if:
  141. .TP
  142. .BR EACCES
  143. The access mode of the open file description associated with
  144. .IR fd
  145. is not O_SEARCH and the permissions of the directory underlying
  146. .IR fd
  147. do not permit directory searches.
  148. .TP
  149. .BR EBADF
  150. The
  151. .IR path
  152. argument does not specify an absolute path and the
  153. .IR fd
  154. argument is neither AT_FDCWD nor a valid file descriptor open for reading
  155. or searching.
  156. .TP
  157. .BR ENOTDIR
  158. The
  159. .IR path
  160. argument is not an absolute path and
  161. .IR fd
  162. is a file descriptor associated with a non-directory file.
  163. .P
  164. These functions may fail if:
  165. .TP
  166. .BR ELOOP
  167. More than
  168. {SYMLOOP_MAX}
  169. symbolic links were encountered during resolution of the
  170. .IR path
  171. argument.
  172. .TP
  173. .BR ENAMETOOLONG
  174. .br
  175. The length of a pathname exceeds
  176. {PATH_MAX},
  177. or pathname resolution of a symbolic link produced an intermediate
  178. result with a length that exceeds
  179. {PATH_MAX}.
  180. .LP
  181. .IR "The following sections are informative."
  182. .SH EXAMPLES
  183. .SS "Creating a Directory"
  184. .P
  185. The following example shows how to create a directory named
  186. .BR /home/cnd/mod1 ,
  187. with read/write/search permissions for owner and group, and with
  188. read/search permissions for others.
  189. .sp
  190. .RS 4
  191. .nf
  192. #include <sys/types.h>
  193. #include <sys/stat.h>
  194. .P
  195. int status;
  196. \&...
  197. status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  198. .fi
  199. .P
  200. .RE
  201. .SH "APPLICATION USAGE"
  202. None.
  203. .SH RATIONALE
  204. The
  205. \fImkdir\fR()
  206. function originated in 4.2 BSD and was added to System V in Release 3.0.
  207. .P
  208. 4.3 BSD detects
  209. .BR [ENAMETOOLONG] .
  210. .P
  211. The POSIX.1\(hy1990 standard required that the group ID of a newly created directory be
  212. set to the group ID of its parent directory or to the effective group
  213. ID of the creating process. FIPS 151\(hy2 required that implementations provide
  214. a way to have the group ID be set to the group ID of the containing
  215. directory, but did not prohibit implementations also supporting a way
  216. to set the group ID to the effective group ID of the creating process.
  217. Conforming applications should not assume which group ID will be used. If
  218. it matters, an application can use
  219. \fIchown\fR()
  220. to set the group ID after the directory is created, or determine under
  221. what conditions the implementation will set the desired group ID.
  222. .P
  223. The purpose of the
  224. \fImkdirat\fR()
  225. function is to create a directory in directories other than the
  226. current working directory without exposure to race conditions. Any part
  227. of the path of a file could be changed in parallel to the call to
  228. \fImkdir\fR(),
  229. resulting in unspecified behavior. By opening a file descriptor for
  230. the target directory and using the
  231. \fImkdirat\fR()
  232. function it can be guaranteed that the newly created directory is
  233. located relative to the desired directory.
  234. .SH "FUTURE DIRECTIONS"
  235. None.
  236. .SH "SEE ALSO"
  237. .IR "\fIchmod\fR\^(\|)",
  238. .IR "\fImkdtemp\fR\^(\|)",
  239. .IR "\fImknod\fR\^(\|)",
  240. .IR "\fIumask\fR\^(\|)"
  241. .P
  242. The Base Definitions volume of POSIX.1\(hy2017,
  243. .IR "\fB<fcntl.h>\fP",
  244. .IR "\fB<sys_stat.h>\fP",
  245. .IR "\fB<sys_types.h>\fP"
  246. .\"
  247. .SH COPYRIGHT
  248. Portions of this text are reprinted and reproduced in electronic form
  249. from IEEE Std 1003.1-2017, Standard for Information Technology
  250. -- Portable Operating System Interface (POSIX), The Open Group Base
  251. Specifications Issue 7, 2018 Edition,
  252. Copyright (C) 2018 by the Institute of
  253. Electrical and Electronics Engineers, Inc and The Open Group.
  254. In the event of any discrepancy between this version and the original IEEE and
  255. The Open Group Standard, the original IEEE and The Open Group Standard
  256. is the referee document. The original Standard can be obtained online at
  257. http://www.opengroup.org/unix/online.html .
  258. .PP
  259. Any typographical or formatting errors that appear
  260. in this page are most likely
  261. to have been introduced during the conversion of the source files to
  262. man page format. To report such errors, see
  263. https://www.kernel.org/doc/man-pages/reporting_bugs.html .