kernel - Add utimensat() support
[dragonfly.git] / lib / libc / sys / utimensat.2
blob9cde4cab59307d213b477a3b11a5d0cbfc4d8967
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 .\" 4. 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 May 20, 2015
35 .Dt UTIMENSAT 2
36 .Os
37 .Sh NAME
38 .Nm utimensat
39 .Nd set file access and modification times
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In sys/stat.h
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 flags"
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
61 .Fa path
62 specifies a relative path,
63 it is relative to the current working directory if
64 .Fa fd
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
85 .Fa times
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.
92 .Fa times
94 .Dv NULL ,
95 this is equivalent to passing
96 a pointer to an array of two timespec structures
97 with both
98 .Va tv_nsec
99 fields set to
100 .Dv UTIME_NOW .
102 If both
103 .Va tv_nsec
104 fields are
105 .Dv UTIME_OMIT ,
106 the timestamps remain unchanged and
107 no permissions are needed for the file itself,
108 although search permissions may be required for the path prefix.
109 The call may or may not succeed if the named file does not exist.
111 If both
112 .Va tv_nsec
113 fields are
114 .Dv UTIME_NOW ,
115 the caller must be the owner of the file, have permission to
116 write the file, or be the super-user.
118 For all other values of the timestamps,
119 the caller must be the owner of the file or be the super-user.
121 The values for the
122 .Fa flag
123 argument of the
124 .Fn utimensat
125 system call
126 are constructed by a bitwise-inclusive OR of flags from the following list,
127 defined in
128 .In fcntl.h :
129 .Bl -tag -width indent
130 .It Dv AT_SYMLINK_NOFOLLOW
132 .Fa path
133 names a symbolic link, the symbolic link's times are changed.
134 By default,
135 .Fn utimensat
136 changes the times of the file referenced by the symbolic link.
138 .Sh RETURN VALUES
139 .Rv -std
140 .Sh ERRORS
141 This system call will fail if:
142 .Bl -tag -width Er
143 .It Bq Er EACCES
145 .Fa times
146 argument is
147 .Dv NULL ,
148 or both
149 .Va tv_nsec
150 values are
151 .Dv UTIME_NOW ,
152 and the effective user ID of the process does not
153 match the owner of the file, and is not the super-user, and write
154 access is denied.
155 .It Bq Er EFAULT
157 .Fa times
158 argument
159 points outside the process's allocated address space.
160 .It Bq Er EINVAL
162 .Va tv_usec
163 component of at least one of the values specified by the
164 .Fa times
165 argument has a value less than 0 or greater than 999999.
166 .It Bq Er EIO
167 An I/O error occurred while reading or writing the affected inode.
168 .It Bq Er EPERM
170 .Fa times
171 argument is not
172 .Dv NULL
173 nor are both
174 .Va tv_nsec
175 values
176 .Dv UTIME_NOW ,
177 nor are both
178 .Va tv_nsec
179 values
180 .Dv UTIME_OMIT
181 and the calling process's effective user ID
182 does not match the owner of the file and is not the super-user.
183 .It Bq Er EPERM
184 The named file has its immutable or append-only flag set, see the
185 .Xr chflags 2
186 manual page for more information.
187 .It Bq Er EROFS
188 The file system containing the file is mounted read-only.
192 .Fn utimensat
193 system call
194 will fail if:
195 .Bl -tag -width Er
196 .It Bq Er EACCES
197 Search permission is denied for a component of the path prefix.
198 .It Bq Er EBADF
200 .Fa path
201 argument does not specify an absolute path and the
202 .Fa fd
203 argument is neither
204 .Dv AT_FDCWD
205 nor a valid file descriptor.
206 .It Bq Er EFAULT
208 .Fa path
209 argument
210 points outside the process's allocated address space.
211 .It Bq Er ELOOP
212 Too many symbolic links were encountered in translating the pathname.
213 .It Bq Er ENAMETOOLONG
214 A component of a pathname exceeded
215 .Dv NAME_MAX
216 characters, or an entire path name exceeded
217 .Dv PATH_MAX
218 characters.
219 .It Bq Er ENOENT
220 The named file does not exist.
221 .It Bq Er ENOTDIR
222 A component of the path prefix is not a directory.
223 .It Bq Er ENOTDIR
225 .Fa path
226 argument is not an absolute path and
227 .Fa fd
228 is neither
229 .Dv AT_FDCWD
230 nor a file descriptor associated with a directory.
231 .It Bq Er ENOTSUP
232 The running kernel does not support this system call and
233 .Dv AT_SYMLINK_NOFOLLOW
234 is used with a path relative to a file descriptor.
236 .Sh SEE ALSO
237 .Xr chflags 2 ,
238 .Xr stat 2 ,
239 .Xr symlink 2 ,
240 .Xr utimes 2 ,
241 .Xr utime 3 ,
242 .Xr symlink 7
243 .Sh STANDARDS
245 .Fn utimensat
246 system call is expected to conform to
247 .St -p1003.1-2008 .
248 .Sh HISTORY
250 .Fn utimensat
251 system call appeared in
252 .Dx 4.1 .