utimensat (2)
Leading comments
$NetBSD: utimes.2,v 1.13 1999/03/22 19:45:11 garbled Exp $ Copyright (c) 1990, 1993 The Regents of the University of California. All rights reserved. Copyright (c) 2012, Jilles Tjoelker Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in bi...
NAME
futimens utimensat - set file access and modification timesLIBRARY
Lb libcSYNOPSIS
In sys/stat.h Ft int Fn futimens int fd const struct timespec times[2] Ft int Fo utimensat Fa int fd Fa const char *path Fa const struct timespec times[2] Fa int flag FcDESCRIPTION
The access and modification times of the file named by Fa path or referenced by Fa fd are changed as specified by the argument Fa times . The inode-change-time of the file is set to the current time.If Fa path specifies a relative path, it is relative to the current working directory if Fa fd is AT_FDCWD and otherwise relative to the directory associated with the file descriptor Fa fd .
The tv_nsec field of a Vt timespec structure can be set to the special value UTIME_NOW to set the current time, or to UTIME_OMIT to leave the time unchanged. In either case, the tv_sec field is ignored.
If Fa times is non- NULL it is assumed to point to an array of two timespec structures. The access time is set to the value of the first element, and the modification time is set to the value of the second element. For file systems that support file birth (creation) times (such as UFS2 ) the birth time will be set to the value of the second element if the second element is older than the currently set birth time. To set both a birth time and a modification time, two calls are required; the first to set the birth time and the second to set the (presumably newer) modification time. Ideally a new system call will be added that allows the setting of all three times at once. If Fa times is NULL this is equivalent to passing a pointer to an array of two timespec structures with both tv_nsec fields set to UTIME_NOW
If both tv_nsec fields are UTIME_OMIT the timestamps remain unchanged and no permissions are needed for the file itself, although search permissions may be required for the path prefix. The call may or may not succeed if the named file does not exist.
If both tv_nsec fields are UTIME_NOW the caller must be the owner of the file, have permission to write the file, or be the super-user.
For all other values of the timestamps, the caller must be the owner of the file or be the super-user.
The values for the Fa flag argument of the Fn utimensat system call are constructed by a bitwise-inclusive OR of flags from the following list, defined in In fcntl.h :
- AT_SYMLINK_NOFOLLOW
- If Fa path names a symbolic link, the symbolic link's times are changed. By default, Fn utimensat changes the times of the file referenced by the symbolic link.
RETURN VALUES
Rv -stdCOMPATIBILITY
If the running kernel does not support this system call, a wrapper emulates it using fstatat(2), futimesat(2) and lutimes(2). As a result, timestamps will be rounded down to the nearest microsecond, UTIME_OMIT is not atomic and AT_SYMLINK_NOFOLLOW is not available with a path relative to a file descriptor.ERRORS
These system calls will fail if:- Bq Er EACCES
- The Fa times argument is NULL or both tv_nsec values are UTIME_NOW and the effective user ID of the process does not match the owner of the file, and is not the super-user, and write access is denied.
- Bq Er EFAULT
- The Fa times argument points outside the process's allocated address space.
- Bq Er EINVAL
- The tv_nsec component of at least one of the values specified by the Fa times argument has a value less than 0 or greater than 999999999 and is not equal to UTIME_NOW or UTIME_OMIT
- Bq Er EIO
- An I/O error occurred while reading or writing the affected inode.
- Bq Er EPERM
- The Fa times argument is not NULL nor are both tv_nsec values UTIME_NOW nor are both tv_nsec values UTIME_OMIT and the calling process's effective user ID does not match the owner of the file and is not the super-user.
- Bq Er EPERM
- The named file has its immutable or append-only flag set, see the chflags(2) manual page for more information.
- Bq Er EROFS
- The file system containing the file is mounted read-only.
The Fn futimens system call will fail if:
- Bq Er EBADF
- The Fa fd argument does not refer to a valid descriptor.
The Fn utimensat system call will fail if:
- Bq Er EACCES
- Search permission is denied for a component of the path prefix.
- Bq Er EBADF
- The Fa path argument does not specify an absolute path and the Fa fd argument is neither AT_FDCWD nor a valid file descriptor.
- Bq Er EFAULT
- The Fa path argument points outside the process's allocated address space.
- Bq Er ELOOP
- Too many symbolic links were encountered in translating the pathname.
- Bq Er ENAMETOOLONG
- A component of a pathname exceeded NAME_MAX characters, or an entire path name exceeded PATH_MAX characters.
- Bq Er ENOENT
- The named file does not exist.
- Bq Er ENOTDIR
- A component of the path prefix is not a directory.
- Bq Er ENOTDIR
- The Fa path argument is not an absolute path and Fa fd is neither AT_FDCWD nor a file descriptor associated with a directory.
- Bq Er ENOTSUP
- The running kernel does not support this system call and AT_SYMLINK_NOFOLLOW is used with a path relative to a file descriptor.