Re: [PATCH] ls: support --time=creation to show/sort birth time
From:
Assaf Gordon
Subject:
Re: [PATCH] ls: support --time=creation to show/sort birth time
Date:
Thu, 2 Jan 2020 15:34:31 -0700
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0
Hello,
On 2020-01-02 2:01 p.m., Pádraig Brady wrote:
On 02/01/2020 20:29, Assaf Gordon wrote:
Regarding "fall back to mtime", I'm seeing the following results
on some systems - not necessarily a bug, but perhaps it's worth
knowing what to expect:
* Debian 10/x86_64, Linux Kernel 4.19.0, glibc 2.28-10,
with ext2 file system (not supporting birthtime):
   $ ./src/ls -l --time=birth /tmp/dummy-ext2/2
   -rw-r--r-- 1 root root 0 Dec 31 1969 /tmp/dummy-ext2/2
Hmm. That suggests that STATX_BTIME is set in the
returned statx mask, but populated with 0 in the structure
({-1,-1} would have printed as '?'). Though you say src/stat
prints '-' in all cases, and the logic should be much the same.
Could you confirm the birth time significant returns for this case.
epoch isn't a bad time to output in this case, but it would
be good to be consistent.
Indeed, the returned "btime" is zero:
----
$ strace -v -e trace=statx ./src/stat /tmp/dummy-ext2/2
-rw-r--r-- 1 root root 0 Dec 31 1969 /tmp/dummy-ext2/2
+++ exited with 0 +++
----
Looking closer at the new ls.c code (** are added for emphasis):
---
do_statx (int fd, const char *name, struct stat *st, int flags,
unsigned int mask)
{
struct statx stx;
**bool want_btime = mask & STATX_BTIME;
int ret = statx (fd, name, flags, mask, &stx);
if (ret >= 0)
{
statx_to_stat (&stx, st);
/* Since we only need one timestamp type,
store birth time in st_mtim. */
** if (mask & STATX_BTIME)
st->st_mtim = statx_timestamp_to_timespec (stx.stx_btime);
** else if (want_btime)
st->st_mtim.tv_sec = st->st_mtim.tv_nsec = -1;
}
return ret;
---
Wouldn't "mask & STATX_BTIME" always be the same as "want_btime",
resulting in the "else if" part never to be executed?
IIUC, "mask" is the requested bitmask.
Comparing with "stat.c:do_stat()", I see:
...