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