Blame man2/utimensat.2

Packit 7cfc04
.\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
Packit 7cfc04
.\" <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH UTIMENSAT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
utimensat, futimens \- change file timestamps with nanosecond precision
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <fcntl.h>           /* Definition of AT_* constants */
Packit 7cfc04
.B #include <sys/stat.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int utimensat(int " dirfd ", const char *" pathname ,
Packit 7cfc04
.BI "              const struct timespec " times "[2], int " flags );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int futimens(int " fd ", const struct timespec " times [2]);
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.ad l
Packit 7cfc04
.PD 0
Packit 7cfc04
.BR utimensat ():
Packit 7cfc04
.RS 4
Packit 7cfc04
.TP 4
Packit 7cfc04
Since glibc 2.10:
Packit 7cfc04
_POSIX_C_SOURCE\ >=\ 200809L
Packit 7cfc04
.TP
Packit 7cfc04
Before glibc 2.10:
Packit 7cfc04
_ATFILE_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.PP
Packit 7cfc04
.BR futimens ():
Packit 7cfc04
.RS 4
Packit 7cfc04
.TP
Packit 7cfc04
Since glibc 2.10:
Packit 7cfc04
_POSIX_C_SOURCE\ >=\ 200809L
Packit 7cfc04
.TP
Packit 7cfc04
Before glibc 2.10:
Packit 7cfc04
_GNU_SOURCE
Packit 7cfc04
.RE
Packit 7cfc04
.PD
Packit 7cfc04
.ad
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
and
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
update the timestamps of a file with nanosecond precision.
Packit 7cfc04
This contrasts with the historical
Packit 7cfc04
.BR utime (2)
Packit 7cfc04
and
Packit 7cfc04
.BR utimes (2),
Packit 7cfc04
which permit only second and microsecond precision, respectively,
Packit 7cfc04
when setting file timestamps.
Packit 7cfc04
.PP
Packit 7cfc04
With
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
the file is specified via the pathname given in
Packit 7cfc04
.IR pathname .
Packit 7cfc04
With
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
the file whose timestamps are to be updated is specified via
Packit 7cfc04
an open file descriptor,
Packit 7cfc04
.IR fd .
Packit 7cfc04
.PP
Packit 7cfc04
For both calls, the new file timestamps are specified in the array
Packit 7cfc04
.IR times :
Packit 7cfc04
.IR times [0]
Packit 7cfc04
specifies the new "last access time" (\fIatime\fP);
Packit 7cfc04
.IR times [1]
Packit 7cfc04
specifies the new "last modification time" (\fImtime\fP).
Packit 7cfc04
Each of the elements of
Packit 7cfc04
.I times
Packit 7cfc04
specifies a time as the number of seconds and nanoseconds
Packit 7cfc04
since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
Packit 7cfc04
This information is conveyed in a structure of the following form:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct timespec {
Packit 7cfc04
    time_t tv_sec;        /* seconds */
Packit 7cfc04
    long   tv_nsec;       /* nanoseconds */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Updated file timestamps are set to the greatest value
Packit 7cfc04
supported by the filesystem that is not greater than the specified time.
Packit 7cfc04
.PP
Packit 7cfc04
If the
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field of one of the
Packit 7cfc04
.I timespec
Packit 7cfc04
structures has the special value
Packit 7cfc04
.BR UTIME_NOW ,
Packit 7cfc04
then the corresponding file timestamp is set to the current time.
Packit 7cfc04
If the
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field of one of the
Packit 7cfc04
.I timespec
Packit 7cfc04
structures has the special value
Packit 7cfc04
.BR UTIME_OMIT ,
Packit 7cfc04
then the corresponding file timestamp is left unchanged.
Packit 7cfc04
In both of these cases, the value of the corresponding
Packit 7cfc04
.I tv_sec
Packit 7cfc04
.\" 2.6.22 was broken: it is not ignored
Packit 7cfc04
field is ignored.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I times
Packit 7cfc04
is NULL, then both timestamps are set to the current time.
Packit 7cfc04
.\"
Packit 7cfc04
.SS Permissions requirements
Packit 7cfc04
To set both file timestamps to the current time (i.e.,
Packit 7cfc04
.I times
Packit 7cfc04
is NULL, or both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields specify
Packit 7cfc04
.BR UTIME_NOW ),
Packit 7cfc04
either:
Packit 7cfc04
.IP 1. 3
Packit 7cfc04
the caller must have write access to the file;
Packit 7cfc04
.\" 2.6.22 was broken here -- for futimens() the check is
Packit 7cfc04
.\" based on whether or not the file descriptor is writable,
Packit 7cfc04
.\" not on whether the caller's effective UID has write
Packit 7cfc04
.\" permission for the file referred to by the descriptor.
Packit 7cfc04
.IP 2.
Packit 7cfc04
the caller's effective user ID must match the owner of the file; or
Packit 7cfc04
.IP 3.
Packit 7cfc04
the caller must have appropriate privileges.
Packit 7cfc04
.PP
Packit 7cfc04
To make any change other than setting both timestamps to the
Packit 7cfc04
current time (i.e.,
Packit 7cfc04
.I times
Packit 7cfc04
is not NULL, and neither
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field is
Packit 7cfc04
.B UTIME_NOW
Packit 7cfc04
.\" 2.6.22 was broken here:
Packit 7cfc04
.\" both must be something other than *either* UTIME_OMIT *or* UTIME_NOW.
Packit 7cfc04
and neither
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field is
Packit 7cfc04
.BR UTIME_OMIT ),
Packit 7cfc04
either condition 2 or 3 above must apply.
Packit 7cfc04
.PP
Packit 7cfc04
If both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields are specified as
Packit 7cfc04
.BR UTIME_OMIT ,
Packit 7cfc04
then no file ownership or permission checks are performed,
Packit 7cfc04
and the file timestamps are not modified,
Packit 7cfc04
but other error conditions may still be detected.
Packit 7cfc04
.\"
Packit 7cfc04
.\"
Packit 7cfc04
.SS utimensat() specifics
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
is relative, then by default it is interpreted relative to the
Packit 7cfc04
directory referred to by the open file descriptor,
Packit 7cfc04
.IR dirfd
Packit 7cfc04
(rather than relative to the current working directory of
Packit 7cfc04
the calling process, as is done by
Packit 7cfc04
.BR utimes (2)
Packit 7cfc04
for a relative pathname).
Packit 7cfc04
See
Packit 7cfc04
.BR openat (2)
Packit 7cfc04
for an explanation of why this can be useful.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
is relative and
Packit 7cfc04
.I dirfd
Packit 7cfc04
is the special value
Packit 7cfc04
.BR AT_FDCWD ,
Packit 7cfc04
then
Packit 7cfc04
.I pathname
Packit 7cfc04
is interpreted relative to the current working
Packit 7cfc04
directory of the calling process (like
Packit 7cfc04
.BR utimes (2)).
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
is absolute, then
Packit 7cfc04
.I dirfd
Packit 7cfc04
is ignored.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flags
Packit 7cfc04
field is a bit mask that may be 0, or include the following constant,
Packit 7cfc04
defined in
Packit 7cfc04
.IR <fcntl.h> :
Packit 7cfc04
.TP
Packit 7cfc04
.B AT_SYMLINK_NOFOLLOW
Packit 7cfc04
If
Packit 7cfc04
.I pathname
Packit 7cfc04
specifies a symbolic link, then update the timestamps of the link,
Packit 7cfc04
rather than the file to which it refers.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
and
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
return 0.
Packit 7cfc04
On error, \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
.I times
Packit 7cfc04
is NULL,
Packit 7cfc04
or both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
values are
Packit 7cfc04
.BR UTIME_NOW ,
Packit 7cfc04
and either:
Packit 7cfc04
.RS
Packit 7cfc04
.IP * 3
Packit 7cfc04
the effective user ID of the caller does not match
Packit 7cfc04
the owner of the file,
Packit 7cfc04
the caller does not have write access to the file,
Packit 7cfc04
and the caller is not privileged
Packit 7cfc04
(Linux: does not have either the
Packit 7cfc04
.B CAP_FOWNER
Packit 7cfc04
or the
Packit 7cfc04
.B CAP_DAC_OVERRIDE
Packit 7cfc04
capability); or,
Packit 7cfc04
.\" But Linux 2.6.22 was broken here.
Packit 7cfc04
.\" Traditionally, utime()/utimes() gives the error EACCES for the case
Packit 7cfc04
.\" where the timestamp pointer argument is NULL (i.e., set both timestamps
Packit 7cfc04
.\" to the current time), and the file is owned by a user other than the
Packit 7cfc04
.\" effective UID of the caller, and the file is not writable by the
Packit 7cfc04
.\" effective UID of the program.  utimensat() also gives this error in the
Packit 7cfc04
.\" same case.  However, in the same circumstances, when utimensat() is
Packit 7cfc04
.\" given a 'times' array in which both tv_nsec fields are UTIME_NOW, which
Packit 7cfc04
.\" provides equivalent functionality to specifying 'times' as NULL, the
Packit 7cfc04
.\" call succeeds.  It should fail with the error EACCES in this case.
Packit 7cfc04
.\"
Packit 7cfc04
.\" POSIX.1-2008 has the following:
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .B EACCES
Packit 7cfc04
.\" .RB ( utimensat ())
Packit 7cfc04
.\" .I fd
Packit 7cfc04
.\" was not opened with
Packit 7cfc04
.\" .B O_SEARCH
Packit 7cfc04
.\" and the permissions of the directory to which
Packit 7cfc04
.\" .I fd
Packit 7cfc04
.\" refers do not allow searches.
Packit 7cfc04
.IP *
Packit 7cfc04
the file is marked immutable (see
Packit 7cfc04
.BR chattr (1)).
Packit 7cfc04
.\" EXT2_IMMUTABLE_FL and similar flags for other filesystems.
Packit 7cfc04
.RE
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.RB ( futimens ())
Packit 7cfc04
.I fd
Packit 7cfc04
is not a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
.I pathname
Packit 7cfc04
is a relative pathname, but
Packit 7cfc04
.I dirfd
Packit 7cfc04
is neither
Packit 7cfc04
.BR AT_FDCWD
Packit 7cfc04
nor a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
.I times
Packit 7cfc04
pointed to an invalid address; or,
Packit 7cfc04
.I dirfd
Packit 7cfc04
was
Packit 7cfc04
.BR AT_FDCWD ,
Packit 7cfc04
and
Packit 7cfc04
.I pathname
Packit 7cfc04
is NULL or an invalid address.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Invalid value in
Packit 7cfc04
.IR flags .
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Invalid value in one of the
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields (value outside range 0 to 999,999,999, and not
Packit 7cfc04
.B UTIME_NOW
Packit 7cfc04
or
Packit 7cfc04
.BR UTIME_OMIT );
Packit 7cfc04
or an invalid value in one of the
Packit 7cfc04
.I tv_sec
Packit 7cfc04
fields.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.\" SUSv4 does not specify this error.
Packit 7cfc04
.I pathname
Packit 7cfc04
is NULL,
Packit 7cfc04
.I dirfd
Packit 7cfc04
is not
Packit 7cfc04
.BR AT_FDCWD ,
Packit 7cfc04
and
Packit 7cfc04
.I flags
Packit 7cfc04
contains
Packit 7cfc04
.BR AT_SYMLINK_NOFOLLOW .
Packit 7cfc04
.TP
Packit 7cfc04
.B ELOOP
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
Too many symbolic links were encountered in resolving
Packit 7cfc04
.IR pathname .
Packit 7cfc04
.TP
Packit 7cfc04
.B ENAMETOOLONG
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
.I pathname
Packit 7cfc04
is too long.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOENT
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
A component of
Packit 7cfc04
.I pathname
Packit 7cfc04
does not refer to an existing directory or file,
Packit 7cfc04
or
Packit 7cfc04
.I pathname
Packit 7cfc04
is an empty string.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTDIR
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
.I pathname
Packit 7cfc04
is a relative pathname, but
Packit 7cfc04
.I dirfd
Packit 7cfc04
is neither
Packit 7cfc04
.B AT_FDCWD
Packit 7cfc04
nor a file descriptor referring to a directory;
Packit 7cfc04
or, one of the prefix components of
Packit 7cfc04
.I pathname
Packit 7cfc04
is not a directory.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The caller attempted to change one or both timestamps to a value
Packit 7cfc04
other than the current time,
Packit 7cfc04
or to change one of the timestamps to the current time while
Packit 7cfc04
leaving the other timestamp unchanged,
Packit 7cfc04
(i.e.,
Packit 7cfc04
.I times
Packit 7cfc04
is not NULL, neither
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field is
Packit 7cfc04
.BR UTIME_NOW ,
Packit 7cfc04
and neither
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
field is
Packit 7cfc04
.BR UTIME_OMIT )
Packit 7cfc04
and either:
Packit 7cfc04
.RS
Packit 7cfc04
.IP * 3
Packit 7cfc04
the caller's effective user ID does not match the owner of file,
Packit 7cfc04
and the caller is not privileged
Packit 7cfc04
(Linux: does not have the
Packit 7cfc04
.BR CAP_FOWNER
Packit 7cfc04
capability); or,
Packit 7cfc04
.IP *
Packit 7cfc04
.\" Linux 2.6.22 was broken here:
Packit 7cfc04
.\" it was not consistent with the old utimes() implementation,
Packit 7cfc04
.\" since the case when both tv_nsec fields are UTIME_NOW, was not
Packit 7cfc04
.\" treated like the (times == NULL) case.
Packit 7cfc04
the file is marked append-only or immutable (see
Packit 7cfc04
.BR chattr (1)).
Packit 7cfc04
.\" EXT2_IMMUTABLE_FL EXT_APPPEND_FL and similar flags for
Packit 7cfc04
.\" other filesystems.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Why the inconsistency (which is described under NOTES) between
Packit 7cfc04
.\" EACCES and EPERM, where only EPERM tests for append-only.
Packit 7cfc04
.\" (This was also so for the older utimes() implementation.)
Packit 7cfc04
.RE
Packit 7cfc04
.TP
Packit 7cfc04
.B EROFS
Packit 7cfc04
The file is on a read-only filesystem.
Packit 7cfc04
.TP
Packit 7cfc04
.B ESRCH
Packit 7cfc04
.RB ( utimensat ())
Packit 7cfc04
Search permission is denied for one of the prefix components of
Packit 7cfc04
.IR pathname .
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
was added to Linux in kernel 2.6.22;
Packit 7cfc04
glibc support was added with version 2.6.
Packit 7cfc04
.PP
Packit 7cfc04
Support for
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
first appeared in glibc 2.6.
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw23 lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR utimensat (),
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
and
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
are specified in POSIX.1-2008.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
obsoletes
Packit 7cfc04
.BR futimesat (2).
Packit 7cfc04
.PP
Packit 7cfc04
On Linux, timestamps cannot be changed for a file marked immutable,
Packit 7cfc04
and the only change permitted for files marked append-only is to
Packit 7cfc04
set the timestamps to the current time.
Packit 7cfc04
(This is consistent with the historical behavior of
Packit 7cfc04
.BR utime (2)
Packit 7cfc04
and
Packit 7cfc04
.BR utimes (2)
Packit 7cfc04
on Linux.)
Packit 7cfc04
.PP
Packit 7cfc04
If both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields are specified as
Packit 7cfc04
.BR UTIME_OMIT ,
Packit 7cfc04
then the Linux implementation of
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
succeeds even if the file referred to by
Packit 7cfc04
.IR dirfd
Packit 7cfc04
and
Packit 7cfc04
.I pathname
Packit 7cfc04
does not exist.
Packit 7cfc04
.SS C library/kernel ABI differences
Packit 7cfc04
On Linux,
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
is a library function implemented on top of the
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
system call.
Packit 7cfc04
To support this, the Linux
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
system call implements a nonstandard feature: if
Packit 7cfc04
.I pathname
Packit 7cfc04
is NULL, then the call modifies the timestamps of
Packit 7cfc04
the file referred to by the file descriptor
Packit 7cfc04
.I dirfd
Packit 7cfc04
(which may refer to any type of file).
Packit 7cfc04
Using this feature, the call
Packit 7cfc04
.I "futimens(fd,\ times)"
Packit 7cfc04
is implemented as:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
utimensat(fd, NULL, times, 0);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Note, however, that the glibc wrapper for
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
disallows passing NULL as the value for
Packit 7cfc04
.IR pathname :
Packit 7cfc04
the wrapper function returns the error
Packit 7cfc04
.IR EINVAL
Packit 7cfc04
in this case.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
Several bugs afflict
Packit 7cfc04
.BR utimensat ()
Packit 7cfc04
and
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
on kernels before 2.6.26.
Packit 7cfc04
These bugs are either nonconformances with the POSIX.1 draft specification
Packit 7cfc04
or inconsistencies with historical Linux behavior.
Packit 7cfc04
.IP * 3
Packit 7cfc04
POSIX.1 specifies that if one of the
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields has the value
Packit 7cfc04
.B UTIME_NOW
Packit 7cfc04
or
Packit 7cfc04
.BR UTIME_OMIT ,
Packit 7cfc04
then the value of the corresponding
Packit 7cfc04
.I tv_sec
Packit 7cfc04
field should be ignored.
Packit 7cfc04
Instead, the value of the
Packit 7cfc04
.I tv_sec
Packit 7cfc04
field is required to be 0 (or the error
Packit 7cfc04
.B EINVAL
Packit 7cfc04
results).
Packit 7cfc04
.IP *
Packit 7cfc04
Various bugs mean that for the purposes of permission checking,
Packit 7cfc04
the case where both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields are set to
Packit 7cfc04
.BR UTIME_NOW
Packit 7cfc04
isn't always treated the same as specifying
Packit 7cfc04
.I times
Packit 7cfc04
as NULL,
Packit 7cfc04
and the case where one
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
value is
Packit 7cfc04
.B UTIME_NOW
Packit 7cfc04
and the other is
Packit 7cfc04
.B UTIME_OMIT
Packit 7cfc04
isn't treated the same as specifying
Packit 7cfc04
.I times
Packit 7cfc04
as a pointer to an array of structures containing arbitrary time values.
Packit 7cfc04
As a result, in some cases:
Packit 7cfc04
a) file timestamps can be updated by a process that shouldn't have
Packit 7cfc04
permission to perform updates;
Packit 7cfc04
b) file timestamps can't be updated by a process that should have
Packit 7cfc04
permission to perform updates; and
Packit 7cfc04
c) the wrong
Packit 7cfc04
.I errno
Packit 7cfc04
value is returned in case of an error.
Packit 7cfc04
.\" Below, the long description of the errors from the previous bullet
Packit 7cfc04
.\" point (abridged because it's too much detail for a man page).
Packit 7cfc04
.\" .IP *
Packit 7cfc04
.\" If one of the
Packit 7cfc04
.\" .I tv_nsec
Packit 7cfc04
.\" fields is
Packit 7cfc04
.\" .BR UTIME_OMIT
Packit 7cfc04
.\" and the other is
Packit 7cfc04
.\" .BR UTIME_NOW ,
Packit 7cfc04
.\" then the error
Packit 7cfc04
.\" .B EPERM
Packit 7cfc04
.\" should occur if the process's effective user ID does not match
Packit 7cfc04
.\" the file owner and the process is not privileged.
Packit 7cfc04
.\" Instead, the call successfully changes one of the timestamps.
Packit 7cfc04
.\" .IP *
Packit 7cfc04
.\" If file is not writable by the effective user ID of the process and
Packit 7cfc04
.\" the process's effective user ID does not match the file owner and
Packit 7cfc04
.\" the process is not privileged,
Packit 7cfc04
.\" and
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" is NULL, then the error
Packit 7cfc04
.\" .B EACCES
Packit 7cfc04
.\" results.
Packit 7cfc04
.\" This error should also occur if
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" points to an array of structures in which both
Packit 7cfc04
.\" .I tv_nsec
Packit 7cfc04
.\" fields are
Packit 7cfc04
.\" .BR UTIME_NOW .
Packit 7cfc04
.\" Instead the call succeeds.
Packit 7cfc04
.\" .IP *
Packit 7cfc04
.\" If a file is marked as append-only (see
Packit 7cfc04
.\" .BR chattr (1)),
Packit 7cfc04
.\" then Linux traditionally
Packit 7cfc04
.\" (i.e.,
Packit 7cfc04
.\" .BR utime (2),
Packit 7cfc04
.\" .BR utimes (2)),
Packit 7cfc04
.\" permits a NULL
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" argument to be used in order to update both timestamps to the current time.
Packit 7cfc04
.\" For consistency,
Packit 7cfc04
.\" .BR utimensat ()
Packit 7cfc04
.\" and
Packit 7cfc04
.\" .BR futimens ()
Packit 7cfc04
.\" should also produce the same result when given a
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" argument that points to an array of structures in which both
Packit 7cfc04
.\" .I tv_nsec
Packit 7cfc04
.\" fields are
Packit 7cfc04
.\" .BR UTIME_NOW .
Packit 7cfc04
.\" Instead, the call fails with the error
Packit 7cfc04
.\" .BR EPERM .
Packit 7cfc04
.\" .IP *
Packit 7cfc04
.\" If a file is marked as immutable (see
Packit 7cfc04
.\" .BR chattr (1)),
Packit 7cfc04
.\" then Linux traditionally
Packit 7cfc04
.\" (i.e.,
Packit 7cfc04
.\" .BR utime (2),
Packit 7cfc04
.\" .BR utimes (2)),
Packit 7cfc04
.\" gives an
Packit 7cfc04
.\" .B EACCES
Packit 7cfc04
.\" error if
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" is NULL.
Packit 7cfc04
.\" For consistency,
Packit 7cfc04
.\" .BR utimensat ()
Packit 7cfc04
.\" and
Packit 7cfc04
.\" .BR futimens ()
Packit 7cfc04
.\" should also produce the same result when given a
Packit 7cfc04
.\" .I times
Packit 7cfc04
.\" that points to an array of structures in which both
Packit 7cfc04
.\" .I tv_nsec
Packit 7cfc04
.\" fields are
Packit 7cfc04
.\" .BR UTIME_NOW .
Packit 7cfc04
.\" Instead, the call fails with the error
Packit 7cfc04
.\" .BR EPERM .
Packit 7cfc04
.IP *
Packit 7cfc04
POSIX.1 says that a process that has \fIwrite access to the file\fP
Packit 7cfc04
can make a call with
Packit 7cfc04
.I times
Packit 7cfc04
as NULL, or with
Packit 7cfc04
.I times
Packit 7cfc04
pointing to an array of structures in which both
Packit 7cfc04
.I tv_nsec
Packit 7cfc04
fields are
Packit 7cfc04
.BR UTIME_NOW ,
Packit 7cfc04
in order to update both timestamps to the current time.
Packit 7cfc04
However,
Packit 7cfc04
.BR futimens ()
Packit 7cfc04
instead checks whether the
Packit 7cfc04
.IR "access mode of the file descriptor allows writing" .
Packit 7cfc04
.\" This means that a process with a file descriptor that allows
Packit 7cfc04
.\" writing could change the timestamps of a file for which it
Packit 7cfc04
.\" does not have write permission;
Packit 7cfc04
.\" conversely, a process with a read-only file descriptor won't
Packit 7cfc04
.\" be able to update the timestamps of a file,
Packit 7cfc04
.\" even if it has write permission on the file.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR chattr (1),
Packit 7cfc04
.BR touch (1),
Packit 7cfc04
.BR futimesat (2),
Packit 7cfc04
.BR openat (2),
Packit 7cfc04
.BR stat (2),
Packit 7cfc04
.BR utimes (2),
Packit 7cfc04
.BR futimes (3),
Packit 7cfc04
.BR inode (7),
Packit 7cfc04
.BR path_resolution (7),
Packit 7cfc04
.BR symlink (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.