utimensat.2 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. .\" $NetBSD: utimes.2,v 1.13 1999/03/22 19:45:11 garbled Exp $
  2. .\"
  3. .\" Copyright (c) 1990, 1993
  4. .\" The Regents of the University of California. All rights reserved.
  5. .\" Copyright (c) 2012, Jilles Tjoelker
  6. .\"
  7. .\" Redistribution and use in source and binary forms, with or without
  8. .\" modification, are permitted provided that the following conditions
  9. .\" are met:
  10. .\" 1. Redistributions of source code must retain the above copyright
  11. .\" notice, this list of conditions and the following disclaimer.
  12. .\" 2. Redistributions in binary form must reproduce the above copyright
  13. .\" notice, this list of conditions and the following disclaimer in the
  14. .\" documentation and/or other materials provided with the distribution.
  15. .\" 3. Neither the name of the University nor the names of its contributors
  16. .\" may be used to endorse or promote products derived from this software
  17. .\" without specific prior written permission.
  18. .\"
  19. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. .\" SUCH DAMAGE.
  30. .\"
  31. .Dd June 12, 2022
  32. .Dt UTIMENSAT 2
  33. .Os
  34. .Sh NAME
  35. .Nm futimens ,
  36. .Nm utimensat
  37. .Nd set file access and modification times
  38. .Sh LIBRARY
  39. .Lb libc
  40. .Sh SYNOPSIS
  41. .In sys/stat.h
  42. .Ft int
  43. .Fn futimens "int fd" "const struct timespec times[2]"
  44. .Ft int
  45. .Fo utimensat
  46. .Fa "int fd"
  47. .Fa "const char *path"
  48. .Fa "const struct timespec times[2]"
  49. .Fa "int flag"
  50. .Fc
  51. .Sh DESCRIPTION
  52. The access and modification times of the file named by
  53. .Fa path
  54. or referenced by
  55. .Fa fd
  56. are changed as specified by the argument
  57. .Fa times .
  58. The inode-change-time of the file is set to the current time.
  59. .Pp
  60. If
  61. .Fa path
  62. specifies a relative path,
  63. it is relative to the current working directory if
  64. .Fa fd
  65. is
  66. .Dv AT_FDCWD
  67. and otherwise relative to the directory associated with the file descriptor
  68. .Fa fd .
  69. .Pp
  70. The
  71. .Va tv_nsec
  72. field of a
  73. .Vt timespec
  74. structure
  75. can be set to the special value
  76. .Dv UTIME_NOW
  77. to set the current time, or to
  78. .Dv UTIME_OMIT
  79. to leave the time unchanged.
  80. In either case, the
  81. .Va tv_sec
  82. field is ignored.
  83. .Pp
  84. If
  85. .Fa times
  86. is
  87. .No non- Ns Dv NULL ,
  88. it is assumed to point to an array of two timespec structures.
  89. The access time is set to the value of the first element, and the
  90. modification time is set to the value of the second element.
  91. For file systems that support file birth (creation) times (such as
  92. .Dv UFS2 ) ,
  93. the birth time will be set to the value of the second element
  94. if the second element is older than the currently set birth time.
  95. To set both a birth time and a modification time,
  96. two calls are required; the first to set the birth time
  97. and the second to set the (presumably newer) modification time.
  98. Ideally a new system call will be added that allows the setting
  99. of all three times at once.
  100. If
  101. .Fa times
  102. is
  103. .Dv NULL ,
  104. this is equivalent to passing
  105. a pointer to an array of two timespec structures
  106. with both
  107. .Va tv_nsec
  108. fields set to
  109. .Dv UTIME_NOW .
  110. .Pp
  111. If both
  112. .Va tv_nsec
  113. fields are
  114. .Dv UTIME_OMIT ,
  115. the timestamps remain unchanged and
  116. no permissions are needed for the file itself,
  117. although search permissions may be required for the path prefix.
  118. The call may or may not succeed if the named file does not exist.
  119. .Pp
  120. If both
  121. .Va tv_nsec
  122. fields are
  123. .Dv UTIME_NOW ,
  124. the caller must be the owner of the file, have permission to
  125. write the file, or be the super-user.
  126. .Pp
  127. For all other values of the timestamps,
  128. the caller must be the owner of the file or be the super-user.
  129. .Pp
  130. The values for the
  131. .Fa flag
  132. argument of the
  133. .Fn utimensat
  134. system call
  135. are constructed by a bitwise-inclusive OR of flags from the following list,
  136. defined in
  137. .In fcntl.h :
  138. .Bl -tag -width indent
  139. .It Dv AT_SYMLINK_NOFOLLOW
  140. If
  141. .Fa path
  142. names a symbolic link, the symbolic link's times are changed.
  143. By default,
  144. .Fn utimensat
  145. changes the times of the file referenced by the symbolic link.
  146. .It Dv AT_RESOLVE_BENEATH
  147. Only walk paths below the directory specified by the
  148. .Ar fd
  149. descriptor.
  150. See the description of the
  151. .Dv O_RESOLVE_BENEATH
  152. flag in the
  153. .Xr open 2
  154. manual page.
  155. .It Dv AT_EMPTY_PATH
  156. If the
  157. .Fa path
  158. argument is an empty string, operate on the file or directory
  159. referenced by the descriptor
  160. .Fa fd .
  161. If
  162. .Fa fd
  163. is equal to
  164. .Dv AT_FDCWD ,
  165. operate on the current working directory.
  166. .El
  167. .Sh RETURN VALUES
  168. .Rv -std
  169. .Sh ERRORS
  170. These system calls will fail if:
  171. .Bl -tag -width Er
  172. .It Bq Er EACCES
  173. The
  174. .Fa times
  175. argument is
  176. .Dv NULL ,
  177. or both
  178. .Va tv_nsec
  179. values are
  180. .Dv UTIME_NOW ,
  181. and the effective user ID of the process does not
  182. match the owner of the file, and is not the super-user, and write
  183. access is denied.
  184. .It Bq Er EFAULT
  185. The
  186. .Fa times
  187. argument
  188. points outside the process's allocated address space.
  189. .It Bq Er EINVAL
  190. The
  191. .Va tv_nsec
  192. component of at least one of the values specified by the
  193. .Fa times
  194. argument has a value less than 0 or greater than 999999999 and is not equal to
  195. .Dv UTIME_NOW
  196. or
  197. .Dv UTIME_OMIT .
  198. .It Bq Er EIO
  199. An I/O error occurred while reading or writing the affected inode.
  200. .It Bq Er EINTEGRITY
  201. Corrupted data was detected while reading from the file system.
  202. .It Bq Er EPERM
  203. The
  204. .Fa times
  205. argument is not
  206. .Dv NULL
  207. nor are both
  208. .Va tv_nsec
  209. values
  210. .Dv UTIME_NOW ,
  211. nor are both
  212. .Va tv_nsec
  213. values
  214. .Dv UTIME_OMIT
  215. and the calling process's effective user ID
  216. does not match the owner of the file and is not the super-user.
  217. .It Bq Er EPERM
  218. The named file has its immutable or append-only flag set, see the
  219. .Xr chflags 2
  220. manual page for more information.
  221. .It Bq Er EROFS
  222. The file system containing the file is mounted read-only.
  223. .El
  224. .Pp
  225. The
  226. .Fn futimens
  227. system call
  228. will fail if:
  229. .Bl -tag -width Er
  230. .It Bq Er EBADF
  231. The
  232. .Fa fd
  233. argument
  234. does not refer to a valid descriptor.
  235. .El
  236. .Pp
  237. The
  238. .Fn utimensat
  239. system call
  240. will fail if:
  241. .Bl -tag -width Er
  242. .It Bq Er EACCES
  243. Search permission is denied for a component of the path prefix.
  244. .It Bq Er EBADF
  245. The
  246. .Fa path
  247. argument does not specify an absolute path and the
  248. .Fa fd
  249. argument is neither
  250. .Dv AT_FDCWD
  251. nor a valid file descriptor.
  252. .It Bq Er EFAULT
  253. The
  254. .Fa path
  255. argument
  256. points outside the process's allocated address space.
  257. .It Bq Er ELOOP
  258. Too many symbolic links were encountered in translating the pathname.
  259. .It Bq Er ENAMETOOLONG
  260. A component of a pathname exceeded
  261. .Dv NAME_MAX
  262. characters, or an entire path name exceeded
  263. .Dv PATH_MAX
  264. characters.
  265. .It Bq Er ENOENT
  266. The named file does not exist.
  267. .It Bq Er ENOTDIR
  268. A component of the path prefix is not a directory.
  269. .It Bq Er ENOTDIR
  270. The
  271. .Fa path
  272. argument is not an absolute path and
  273. .Fa fd
  274. is neither
  275. .Dv AT_FDCWD
  276. nor a file descriptor associated with a directory.
  277. .It Bq Er ENOTCAPABLE
  278. .Fa path
  279. is an absolute path,
  280. or contained a ".." component leading to a
  281. directory outside of the directory hierarchy specified by
  282. .Fa fd ,
  283. and the process is in capability mode or the
  284. .Dv AT_RESOLVE_BENEATH
  285. flag was specified.
  286. .El
  287. .Sh SEE ALSO
  288. .Xr chflags 2 ,
  289. .Xr stat 2 ,
  290. .Xr symlink 2 ,
  291. .Xr utimes 2 ,
  292. .Xr utime 3 ,
  293. .Xr symlink 7
  294. .Sh STANDARDS
  295. The
  296. .Fn futimens
  297. and
  298. .Fn utimensat
  299. system calls are expected to conform to
  300. .St -p1003.1-2008 .
  301. .Sh HISTORY
  302. The
  303. .Fn futimens
  304. and
  305. .Fn utimensat
  306. system calls appeared in
  307. .Fx 10.3 .