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