xref: /freebsd/lib/libsys/utimes.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.\"
6*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
7*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
8*8269e767SBrooks Davis.\" are met:
9*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
12*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
13*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
14*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
15*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
16*8269e767SBrooks Davis.\"    without specific prior written permission.
17*8269e767SBrooks Davis.\"
18*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*8269e767SBrooks Davis.\" SUCH DAMAGE.
29*8269e767SBrooks Davis.\"
30*8269e767SBrooks Davis.Dd March 30, 2020
31*8269e767SBrooks Davis.Dt UTIMES 2
32*8269e767SBrooks Davis.Os
33*8269e767SBrooks Davis.Sh NAME
34*8269e767SBrooks Davis.Nm utimes ,
35*8269e767SBrooks Davis.Nm lutimes ,
36*8269e767SBrooks Davis.Nm futimes ,
37*8269e767SBrooks Davis.Nm futimesat
38*8269e767SBrooks Davis.Nd set file access and modification times
39*8269e767SBrooks Davis.Sh LIBRARY
40*8269e767SBrooks Davis.Lb libc
41*8269e767SBrooks Davis.Sh SYNOPSIS
42*8269e767SBrooks Davis.In sys/time.h
43*8269e767SBrooks Davis.Ft int
44*8269e767SBrooks Davis.Fn utimes "const char *path" "const struct timeval *times"
45*8269e767SBrooks Davis.Ft int
46*8269e767SBrooks Davis.Fn lutimes "const char *path" "const struct timeval *times"
47*8269e767SBrooks Davis.Ft int
48*8269e767SBrooks Davis.Fn futimes "int fd" "const struct timeval *times"
49*8269e767SBrooks Davis.Ft int
50*8269e767SBrooks Davis.Fn futimesat "int fd" "const char *path" "const struct timeval times[2]"
51*8269e767SBrooks Davis.Sh DESCRIPTION
52*8269e767SBrooks Davis.Bf -symbolic
53*8269e767SBrooks DavisThese interfaces are obsoleted by
54*8269e767SBrooks Davis.Xr futimens 2
55*8269e767SBrooks Davisand
56*8269e767SBrooks Davis.Xr utimensat 2
57*8269e767SBrooks Davisbecause they are not accurate to nanoseconds.
58*8269e767SBrooks Davis.Ef
59*8269e767SBrooks Davis.Pp
60*8269e767SBrooks DavisThe access and modification times of the file named by
61*8269e767SBrooks Davis.Fa path
62*8269e767SBrooks Davisor referenced by
63*8269e767SBrooks Davis.Fa fd
64*8269e767SBrooks Davisare changed as specified by the argument
65*8269e767SBrooks Davis.Fa times .
66*8269e767SBrooks Davis.Pp
67*8269e767SBrooks DavisIf
68*8269e767SBrooks Davis.Fa times
69*8269e767SBrooks Davisis
70*8269e767SBrooks Davis.Dv NULL ,
71*8269e767SBrooks Davisthe access and modification times are set to the current time.
72*8269e767SBrooks DavisThe caller must be the owner of the file, have permission to
73*8269e767SBrooks Daviswrite the file, or be the super-user.
74*8269e767SBrooks Davis.Pp
75*8269e767SBrooks DavisIf
76*8269e767SBrooks Davis.Fa times
77*8269e767SBrooks Davisis
78*8269e767SBrooks Davis.No non- Ns Dv NULL ,
79*8269e767SBrooks Davisit is assumed to point to an array of two timeval structures.
80*8269e767SBrooks DavisThe access time is set to the value of the first element, and the
81*8269e767SBrooks Davismodification time is set to the value of the second element.
82*8269e767SBrooks DavisFor file systems that support file birth (creation) times (such as
83*8269e767SBrooks Davis.Dv UFS2 ) ,
84*8269e767SBrooks Davisthe birth time will be set to the value of the second element
85*8269e767SBrooks Davisif the second element is older than the currently set birth time.
86*8269e767SBrooks DavisTo set both a birth time and a modification time,
87*8269e767SBrooks Davistwo calls are required; the first to set the birth time
88*8269e767SBrooks Davisand the second to set the (presumably newer) modification time.
89*8269e767SBrooks DavisIdeally a new system call will be added that allows the setting
90*8269e767SBrooks Davisof all three times at once.
91*8269e767SBrooks DavisThe caller must be the owner of the file or be the super-user.
92*8269e767SBrooks Davis.Pp
93*8269e767SBrooks DavisIn either case, the inode-change-time of the file is set to the current
94*8269e767SBrooks Davistime.
95*8269e767SBrooks Davis.Pp
96*8269e767SBrooks DavisThe
97*8269e767SBrooks Davis.Fn lutimes
98*8269e767SBrooks Davissystem call
99*8269e767SBrooks Davisis like
100*8269e767SBrooks Davis.Fn utimes
101*8269e767SBrooks Davisexcept in the case where the named file is a symbolic link,
102*8269e767SBrooks Davisin which case
103*8269e767SBrooks Davis.Fn lutimes
104*8269e767SBrooks Davischanges the access and modification times of the link,
105*8269e767SBrooks Daviswhile
106*8269e767SBrooks Davis.Fn utimes
107*8269e767SBrooks Davischanges the times of the file the link references.
108*8269e767SBrooks Davis.Pp
109*8269e767SBrooks DavisThe
110*8269e767SBrooks Davis.Fn futimesat
111*8269e767SBrooks Davissystem call is equivalent to
112*8269e767SBrooks Davis.Fn utimes
113*8269e767SBrooks Davisexcept in the case where
114*8269e767SBrooks Davis.Fa path
115*8269e767SBrooks Davisspecifies a relative path.
116*8269e767SBrooks DavisIn this case the access and modification time
117*8269e767SBrooks Davisis set to that of a file relative to the directory associated with the file
118*8269e767SBrooks Davisdescriptor
119*8269e767SBrooks Davis.Fa fd
120*8269e767SBrooks Davisinstead of the current working directory.
121*8269e767SBrooks DavisIf
122*8269e767SBrooks Davis.Fn futimesat
123*8269e767SBrooks Davisis passed the special value
124*8269e767SBrooks Davis.Dv AT_FDCWD
125*8269e767SBrooks Davisin the
126*8269e767SBrooks Davis.Fa fd
127*8269e767SBrooks Davisparameter, the current working directory is used and the behavior
128*8269e767SBrooks Davisis identical to a call to
129*8269e767SBrooks Davis.Fn utimes .
130*8269e767SBrooks Davis.Sh RETURN VALUES
131*8269e767SBrooks Davis.Rv -std
132*8269e767SBrooks Davis.Sh ERRORS
133*8269e767SBrooks DavisAll of the system call will fail if:
134*8269e767SBrooks Davis.Bl -tag -width Er
135*8269e767SBrooks Davis.It Bq Er EACCES
136*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix.
137*8269e767SBrooks Davis.It Bq Er EACCES
138*8269e767SBrooks DavisThe
139*8269e767SBrooks Davis.Fa times
140*8269e767SBrooks Davisargument is
141*8269e767SBrooks Davis.Dv NULL
142*8269e767SBrooks Davisand the effective user ID of the process does not
143*8269e767SBrooks Davismatch the owner of the file, and is not the super-user, and write
144*8269e767SBrooks Davisaccess is denied.
145*8269e767SBrooks Davis.It Bq Er EFAULT
146*8269e767SBrooks DavisThe
147*8269e767SBrooks Davis.Fa path
148*8269e767SBrooks Davisor
149*8269e767SBrooks Davis.Fa times
150*8269e767SBrooks Davisargument
151*8269e767SBrooks Davispoints outside the process's allocated address space.
152*8269e767SBrooks Davis.It Bq Er EFAULT
153*8269e767SBrooks DavisThe
154*8269e767SBrooks Davis.Fa times
155*8269e767SBrooks Davisargument
156*8269e767SBrooks Davispoints outside the process's allocated address space.
157*8269e767SBrooks Davis.It Bq Er EINVAL
158*8269e767SBrooks DavisThe
159*8269e767SBrooks Davis.Va tv_usec
160*8269e767SBrooks Daviscomponent of at least one of the values specified by the
161*8269e767SBrooks Davis.Fa times
162*8269e767SBrooks Davisargument has a value less than 0 or greater than 999999.
163*8269e767SBrooks Davis.It Bq Er EIO
164*8269e767SBrooks DavisAn I/O error occurred while reading or writing the affected inode.
165*8269e767SBrooks Davis.It Bq Er EINTEGRITY
166*8269e767SBrooks DavisCorrupted data was detected while reading from the file system.
167*8269e767SBrooks Davis.It Bq Er ELOOP
168*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname.
169*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
170*8269e767SBrooks DavisA component of a pathname exceeded
171*8269e767SBrooks Davis.Dv NAME_MAX
172*8269e767SBrooks Davischaracters, or an entire path name exceeded
173*8269e767SBrooks Davis.Dv PATH_MAX
174*8269e767SBrooks Davischaracters.
175*8269e767SBrooks Davis.It Bq Er ENOENT
176*8269e767SBrooks DavisThe named file does not exist.
177*8269e767SBrooks Davis.It Bq Er ENOTDIR
178*8269e767SBrooks DavisA component of the path prefix is not a directory.
179*8269e767SBrooks Davis.It Bq Er EPERM
180*8269e767SBrooks DavisThe
181*8269e767SBrooks Davis.Fa times
182*8269e767SBrooks Davisargument is not
183*8269e767SBrooks Davis.Dv NULL
184*8269e767SBrooks Davisand the calling process's effective user ID
185*8269e767SBrooks Davisdoes not match the owner of the file and is not the super-user.
186*8269e767SBrooks Davis.It Bq Er EPERM
187*8269e767SBrooks DavisThe named file has its immutable or append-only flags set.
188*8269e767SBrooks DavisSee the
189*8269e767SBrooks Davis.Xr chflags 2
190*8269e767SBrooks Davismanual page for more information.
191*8269e767SBrooks Davis.It Bq Er EROFS
192*8269e767SBrooks DavisThe file system containing the file is mounted read-only.
193*8269e767SBrooks Davis.El
194*8269e767SBrooks Davis.Pp
195*8269e767SBrooks DavisThe
196*8269e767SBrooks Davis.Fn futimes
197*8269e767SBrooks Davissystem call
198*8269e767SBrooks Daviswill fail if:
199*8269e767SBrooks Davis.Bl -tag -width Er
200*8269e767SBrooks Davis.It Bq Er EBADF
201*8269e767SBrooks DavisThe
202*8269e767SBrooks Davis.Fa fd
203*8269e767SBrooks Davisargument
204*8269e767SBrooks Davisdoes not refer to a valid descriptor.
205*8269e767SBrooks Davis.El
206*8269e767SBrooks Davis.Pp
207*8269e767SBrooks DavisIn addition to the errors returned by the
208*8269e767SBrooks Davis.Fn utimes ,
209*8269e767SBrooks Davisthe
210*8269e767SBrooks Davis.Fn futimesat
211*8269e767SBrooks Davismay fail if:
212*8269e767SBrooks Davis.Bl -tag -width Er
213*8269e767SBrooks Davis.It Bq Er EBADF
214*8269e767SBrooks DavisThe
215*8269e767SBrooks Davis.Fa path
216*8269e767SBrooks Davisargument does not specify an absolute path and the
217*8269e767SBrooks Davis.Fa fd
218*8269e767SBrooks Davisargument is neither
219*8269e767SBrooks Davis.Dv AT_FDCWD
220*8269e767SBrooks Davisnor a valid file descriptor open for searching.
221*8269e767SBrooks Davis.It Bq Er ENOTDIR
222*8269e767SBrooks DavisThe
223*8269e767SBrooks Davis.Fa path
224*8269e767SBrooks Davisargument is not an absolute path and
225*8269e767SBrooks Davis.Fa fd
226*8269e767SBrooks Davisis neither
227*8269e767SBrooks Davis.Dv AT_FDCWD
228*8269e767SBrooks Davisnor a file descriptor associated with a directory.
229*8269e767SBrooks Davis.El
230*8269e767SBrooks Davis.Sh SEE ALSO
231*8269e767SBrooks Davis.Xr chflags 2 ,
232*8269e767SBrooks Davis.Xr stat 2 ,
233*8269e767SBrooks Davis.Xr utimensat 2 ,
234*8269e767SBrooks Davis.Xr utime 3
235*8269e767SBrooks Davis.Sh STANDARDS
236*8269e767SBrooks DavisThe
237*8269e767SBrooks Davis.Fn utimes
238*8269e767SBrooks Davisfunction is expected to conform to
239*8269e767SBrooks Davis.St -xpg4.2 .
240*8269e767SBrooks DavisThe
241*8269e767SBrooks Davis.Fn futimesat
242*8269e767SBrooks Davissystem call follows The Open Group Extended API Set 2 specification
243*8269e767SBrooks Davisbut was replaced by
244*8269e767SBrooks Davis.Fn utimensat
245*8269e767SBrooks Davisin
246*8269e767SBrooks Davis.St -p1003.1-2008 .
247*8269e767SBrooks Davis.Sh HISTORY
248*8269e767SBrooks DavisThe
249*8269e767SBrooks Davis.Fn utimes
250*8269e767SBrooks Davissystem call appeared in
251*8269e767SBrooks Davis.Bx 4.2 .
252*8269e767SBrooks DavisThe
253*8269e767SBrooks Davis.Fn futimes
254*8269e767SBrooks Davisand
255*8269e767SBrooks Davis.Fn lutimes
256*8269e767SBrooks Davissystem calls first appeared in
257*8269e767SBrooks Davis.Fx 3.0 .
258*8269e767SBrooks DavisThe
259*8269e767SBrooks Davis.Fn futimesat
260*8269e767SBrooks Davissystem call appeared in
261*8269e767SBrooks Davis.Fx 8.0 .
262