utimensat(2) System Calls Manual utimensat(2) utimensat, futimens - LIBRARY Standard C library (libc, -lc) #include /* AT_* */ #include int utimensat(int dirfd, const char *pathname, const struct timespec times[_Nullable 2], int flags); int futimens(int fd, const struct timespec times[_Nullable 2]); glibc (. feature_test_macros(7)): utimensat(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _ATFILE_SOURCE futimens(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _BSD_SOURCE utimensat() futimens() . utime(2) utimes(2), , . utimensat() pathname . futimens() fd. For both calls, the new file timestamps are specified in the array times: times[0] specifies the new "last access time" (atime); times[1] specifies the new "last modification time" (mtime). Each of the elements of times specifies a time as the number of seconds and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). This information is conveyed in a timespec(3) structure. , , . tv_nsec timespec UTIME_NOW, . tv_nsec timespec UTIME_OMIT, . tv_sec . times NULL, . The status change time (ctime) will be set to the current time, even if the other time stamps don't actually change. (.., times NULL, tv_nsec UTIME_NOW) : o ; o ; o . (. ., times NULL, tv_nsec UTIME_NOW UTIME_OMIT) 2 3. tv_nsec UTIME_OMIT, , , . utimensat() pathname , , , dirfd ( , utimes(2) ). openat(2) . pathname dirfd AT_FDCWD, pathname ( utimes(2)). pathname , dirfd . The flags argument is a bit mask created by ORing together zero or more of the following values defined in : AT_EMPTY_PATH (since Linux 5.8) If pathname is an empty string, operate on the file referred to by dirfd (which may have been obtained using the open(2) O_PATH flag). In this case, dirfd can refer to any type of file, not just a directory. If dirfd is AT_FDCWD, the call operates on the current working directory. This flag is Linux-specific; define _GNU_SOURCE to obtain its definition. AT_SYMLINK_NOFOLLOW pathname , , , . utimensat() futimens() 0. -1, errno . EACCES times is NULL, or both tv_nsec values are UTIME_NOW, and the effective user ID of the caller does not match the owner of the file, the caller does not have write access to the file, and the caller is not privileged (Linux: does not have either the CAP_FOWNER or the CAP_DAC_OVERRIDE capability). EBADF (futimens()) fd . EBADF (utimensat()) pathname , dirfd AT_FDCWD . EFAULT times ; dirfd AT_FDCWD pathname NULL . EINVAL flags. EINVAL Invalid value in one of the tv_nsec fields (value outside range [0, 999,999,999], and not UTIME_NOW or UTIME_OMIT); or an invalid value in one of the tv_sec fields. EINVAL pathname NULL, dirfd AT_FDCWD flags AT_SYMLINK_NOFOLLOW. ELOOP (utimensat()) pathname . ENAMETOOLONG (utimensat()) pathname. ENOENT (utimensat()) pathname , pathname . ENOTDIR (utimensat()) pathname , dirfd AT_FDCWD , ; pathname . EPERM , , , (. ., times NULL, tv_nsec UTIME_NOW, tv_nsec UTIME_OMIT) : o , (Linux: CAP_FOWNER); o (. chattr(1)). EROFS , . ESRCH (utimensat()) pathname . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |utimensat(), futimens() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ C ABI Linux, futimens() utimensat(). Linux- utimensat() : pathname NULL, dirfd ( ). futimens(fd, times) : utimensat(fd, NULL, times, 0); , glibc utimensat() NULL pathname -- EINVAL. POSIX.1-2008. utimensat() Linux 2.6.22, glibc 2.6. POSIX.1-2008. futimens() glibc 2.6. POSIX.1-2008. utimensat() futimesat(2). Linux, , (immutable), , , ( Linux utime(2) utimes(2)). tv_nsec UTIME_OMIT, utimensat() Linux , , , dirfd pathname, . Several bugs afflict utimensat() and futimens() before Linux 2.6.26. These bugs are either nonconformances with the POSIX.1 draft specification or inconsistencies with historical Linux behavior. o POSIX.1 , tv_nsec UTIME_NOW UTIME_OMIT, tv_sec . , tv_sec 0 ( EINVAL). o : , tv_nsec UTIME_NOW, times NULL, , tv_nsec UTIME_NOW, -- UTIME_OMIT, times , . : ) , ; ) , ; ) errno. o POSIX.1 , , times NULL, times, , tv_nsec UTIME_NOW. futimens() . . chattr(1), touch(1), futimesat(2), openat(2), stat(2), utimes(2), futimes(3), timespec(3), inode(7), path_resolution(7), symlink(7) Azamat Hackimov , Dmitriy Ovchinnikov , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 1 2024 . utimensat(2)