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