[MacPorts] #58729: legacy-support missing futimens() (and utimensat)
MacPorts
noreply at macports.org
Fri Jan 29 21:57:01 UTC 2021
#58729: legacy-support missing futimens() (and utimensat)
-----------------------------+----------------------
Reporter: RJVB | Owner: kencu
Type: enhancement | Status: assigned
Priority: Normal | Milestone:
Component: ports | Version:
Resolution: | Keywords:
Port: legacy-support |
-----------------------------+----------------------
Changes (by Ionic):
* cc: Ionic (added)
Comment:
Emulating that should be safe.
POSIX/SUS specifies:
>For `futimens`() and `utimensat`(), the times argument is an array of two
**timespec** structures. The first array member represents the date and
time of last access, and the second member represents the date and time of
last modification. The times in the **timespec** structure are measured in
seconds and nanoseconds since the Epoch. The file's relevant timestamp
shall be set to the greatest value supported by the file system that is
not greater than the specified time.
>
>If the `tv_nsec` field of a **timespec** structure has the special value
UTIME_NOW, the file's relevant timestamp shall be set to the greatest
value supported by the file system that is not greater than the current
time. If the `tv_nsec` field has the special value UTIME_OMIT, the file's
relevant timestamp shall not be changed. In either case, the `tv_sec`
field shall be ignored.
>
>If the `times` argument is a null pointer, both the access and
modification timestamps shall be set to the greatest value supported by
the file system that is not greater than the current time.
Thus, SUS does have provisions for file systems not supporting such low
resolutions. That argument is moot.
I've looked up the relevant source code in 10.13. That would be
[http://web.archive.org/web/20210129201556/https://opensource.apple.com/source/xnu/xnu-4570.71.2/bsd/sys/stat.h.auto.html
include/sys/stat.h] and
[http://web.archive.org/web/20210129201720/https://opensource.apple.com/source/xnu/xnu-4570.71.2/libsyscall/wrappers/utimensat.c.auto.html
utimensat.c].
Ironically, if the comment is right and I read the code correctly, macOS
10.13 does support nanosecond-based time resolution for
`futimens`/`utimensat` only if passed-in directly, but not for the special
`NOW` value, since `gettimeofday` cannot return those. Given that, I think
that emulating it with microseconds isn't a big deal.
Further, we don't even really need to emulate it. We can take the code
verbatim for 10.6 - 10.12. That'll be APSL 2.0, but I guess that's fine.
For 10.6 and below, things are a bit more complicated.
`utimensat` looks less problematic, since it uses `setattrlistat`, which
should be supported even by older operating systems.
`futimens` uses `fsetattrlist`, which is only available on 10.6+. This
said, I guess we could likewise just copy its code, since it's likely
based on `setattrlistat`.
I'd have to look deeper at older systems to find out if all support
`ATTR_BIT_MAP_COUNT`, but I cannot imagine that they don't.
All in all, it sounds very doable.
Thoughts?
--
Ticket URL: <https://trac.macports.org/ticket/58729#comment:11>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list