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