]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/utimensat.2
OpenSSL: update to 3.0.10
[FreeBSD/FreeBSD.git] / lib / libc / sys / utimensat.2
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 .\"     @(#)utimes.2    8.1 (Berkeley) 6/4/93
32 .\" $FreeBSD$
33 .\"
34 .Dd June 12, 2022
35 .Dt UTIMENSAT 2
36 .Os
37 .Sh NAME
38 .Nm futimens ,
39 .Nm utimensat
40 .Nd set file access and modification times
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/stat.h
45 .Ft int
46 .Fn futimens "int fd" "const struct timespec times[2]"
47 .Ft int
48 .Fo utimensat
49 .Fa "int fd"
50 .Fa "const char *path"
51 .Fa "const struct timespec times[2]"
52 .Fa "int flag"
53 .Fc
54 .Sh DESCRIPTION
55 The access and modification times of the file named by
56 .Fa path
57 or referenced by
58 .Fa fd
59 are changed as specified by the argument
60 .Fa times .
61 The inode-change-time of the file is set to the current time.
62 .Pp
63 If
64 .Fa path
65 specifies a relative path,
66 it is relative to the current working directory if
67 .Fa fd
68 is
69 .Dv AT_FDCWD
70 and otherwise relative to the directory associated with the file descriptor
71 .Fa fd .
72 .Pp
73 The
74 .Va tv_nsec
75 field of a
76 .Vt timespec
77 structure
78 can be set to the special value
79 .Dv UTIME_NOW
80 to set the current time, or to
81 .Dv UTIME_OMIT
82 to leave the time unchanged.
83 In either case, the
84 .Va tv_sec
85 field is ignored.
86 .Pp
87 If
88 .Fa times
89 is
90 .No non- Ns Dv NULL ,
91 it is assumed to point to an array of two timespec structures.
92 The access time is set to the value of the first element, and the
93 modification time is set to the value of the second element.
94 For file systems that support file birth (creation) times (such as
95 .Dv UFS2 ) ,
96 the birth time will be set to the value of the second element
97 if the second element is older than the currently set birth time.
98 To set both a birth time and a modification time,
99 two calls are required; the first to set the birth time
100 and the second to set the (presumably newer) modification time.
101 Ideally a new system call will be added that allows the setting
102 of all three times at once.
103 If
104 .Fa times
105 is
106 .Dv NULL ,
107 this is equivalent to passing
108 a pointer to an array of two timespec structures
109 with both
110 .Va tv_nsec
111 fields set to
112 .Dv UTIME_NOW .
113 .Pp
114 If both
115 .Va tv_nsec
116 fields are
117 .Dv UTIME_OMIT ,
118 the timestamps remain unchanged and
119 no permissions are needed for the file itself,
120 although search permissions may be required for the path prefix.
121 The call may or may not succeed if the named file does not exist.
122 .Pp
123 If both
124 .Va tv_nsec
125 fields are
126 .Dv UTIME_NOW ,
127 the caller must be the owner of the file, have permission to
128 write the file, or be the super-user.
129 .Pp
130 For all other values of the timestamps,
131 the caller must be the owner of the file or be the super-user.
132 .Pp
133 The values for the
134 .Fa flag
135 argument of the
136 .Fn utimensat
137 system call
138 are constructed by a bitwise-inclusive OR of flags from the following list,
139 defined in
140 .In fcntl.h :
141 .Bl -tag -width indent
142 .It Dv AT_SYMLINK_NOFOLLOW
143 If
144 .Fa path
145 names a symbolic link, the symbolic link's times are changed.
146 By default,
147 .Fn utimensat
148 changes the times of the file referenced by the symbolic link.
149 .It Dv AT_RESOLVE_BENEATH
150 Only walk paths below the directory specified by the
151 .Ar fd
152 descriptor.
153 See the description of the
154 .Dv O_RESOLVE_BENEATH
155 flag in the
156 .Xr open 2
157 manual page.
158 .It Dv AT_EMPTY_PATH
159 If the
160 .Fa path
161 argument is an empty string, operate on the file or directory
162 referenced by the descriptor
163 .Fa fd .
164 If
165 .Fa fd
166 is equal to
167 .Dv AT_FDCWD ,
168 operate on the current working directory.
169 .El
170 .Sh RETURN VALUES
171 .Rv -std
172 .Sh ERRORS
173 These system calls will fail if:
174 .Bl -tag -width Er
175 .It Bq Er EACCES
176 The
177 .Fa times
178 argument is
179 .Dv NULL ,
180 or both
181 .Va tv_nsec
182 values are
183 .Dv UTIME_NOW ,
184 and the effective user ID of the process does not
185 match the owner of the file, and is not the super-user, and write
186 access is denied.
187 .It Bq Er EFAULT
188 The
189 .Fa times
190 argument
191 points outside the process's allocated address space.
192 .It Bq Er EINVAL
193 The
194 .Va tv_nsec
195 component of at least one of the values specified by the
196 .Fa times
197 argument has a value less than 0 or greater than 999999999 and is not equal to
198 .Dv UTIME_NOW
199 or
200 .Dv UTIME_OMIT .
201 .It Bq Er EIO
202 An I/O error occurred while reading or writing the affected inode.
203 .It Bq Er EINTEGRITY
204 Corrupted data was detected while reading from the file system.
205 .It Bq Er EPERM
206 The
207 .Fa times
208 argument is not
209 .Dv NULL
210 nor are both
211 .Va tv_nsec
212 values
213 .Dv UTIME_NOW ,
214 nor are both
215 .Va tv_nsec
216 values
217 .Dv UTIME_OMIT
218 and the calling process's effective user ID
219 does not match the owner of the file and is not the super-user.
220 .It Bq Er EPERM
221 The named file has its immutable or append-only flag set, see the
222 .Xr chflags 2
223 manual page for more information.
224 .It Bq Er EROFS
225 The file system containing the file is mounted read-only.
226 .El
227 .Pp
228 The
229 .Fn futimens
230 system call
231 will fail if:
232 .Bl -tag -width Er
233 .It Bq Er EBADF
234 The
235 .Fa fd
236 argument
237 does not refer to a valid descriptor.
238 .El
239 .Pp
240 The
241 .Fn utimensat
242 system call
243 will fail if:
244 .Bl -tag -width Er
245 .It Bq Er EACCES
246 Search permission is denied for a component of the path prefix.
247 .It Bq Er EBADF
248 The
249 .Fa path
250 argument does not specify an absolute path and the
251 .Fa fd
252 argument is neither
253 .Dv AT_FDCWD
254 nor a valid file descriptor.
255 .It Bq Er EFAULT
256 The
257 .Fa path
258 argument
259 points outside the process's allocated address space.
260 .It Bq Er ELOOP
261 Too many symbolic links were encountered in translating the pathname.
262 .It Bq Er ENAMETOOLONG
263 A component of a pathname exceeded
264 .Dv NAME_MAX
265 characters, or an entire path name exceeded
266 .Dv PATH_MAX
267 characters.
268 .It Bq Er ENOENT
269 The named file does not exist.
270 .It Bq Er ENOTDIR
271 A component of the path prefix is not a directory.
272 .It Bq Er ENOTDIR
273 The
274 .Fa path
275 argument is not an absolute path and
276 .Fa fd
277 is neither
278 .Dv AT_FDCWD
279 nor a file descriptor associated with a directory.
280 .It Bq Er ENOTCAPABLE
281 .Fa path
282 is an absolute path,
283 or contained a ".." component leading to a
284 directory outside of the directory hierarchy specified by
285 .Fa fd ,
286 and the process is in capability mode or the
287 .Dv AT_RESOLVE_BENEATH
288 flag was specified.
289 .El
290 .Sh SEE ALSO
291 .Xr chflags 2 ,
292 .Xr stat 2 ,
293 .Xr symlink 2 ,
294 .Xr utimes 2 ,
295 .Xr utime 3 ,
296 .Xr symlink 7
297 .Sh STANDARDS
298 The
299 .Fn futimens
300 and
301 .Fn utimensat
302 system calls are expected to conform to
303 .St -p1003.1-2008 .
304 .Sh HISTORY
305 The
306 .Fn futimens
307 and
308 .Fn utimensat
309 system calls appeared in
310 .Fx 10.3 .