Skip to content

Conversation

@drinkcat
Copy link
Collaborator

@drinkcat drinkcat commented Jul 27, 2025

Mostly common code elimination, and fix a crash if a file change time (ctime) is <1970 (not a terribly common thing ,-P)


fsext: Fix metadata_get_time for change time (ctime) before 1970

Useful for archaeologists and time travellers, do not crash if
ctime is before 1970.

Creating a file with such a change time is a bit challenging
(touch can't change that), so we can't easily add end-to-end
tests.

Steps to create a filesystem with a file x with birth/change
time in 1960.

dd if=/dev/zero bs=100M count=0 seek=1 of=ext4
mkfs.ext4 ext4
sudo mount ext4 mnt
touch mnt/x
umount mnt
echo "set_inode_field x ctime 196001010101" | debugfs -w ext4
echo "set_inode_field x ctime_extra 1234" | debugfs -w ext4
echo "set_inode_field x crtime 196001010101" | debugfs -w ext4
echo "set_inode_field x crtime_extra 0x123400" | debugfs -w ext4
sudo mount ext4 mnt
$ cargo run -p uu_stat mnt/x
  File: mnt/x
  size: 0         	Blocks: 0          IO Block: 1024   regular empty file
Device: 700h/1792d	Inode: 13          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2025-07-26 19:52:00.849821694 +0800
Modify: 2025-07-26 19:52:00.849821694 +0800
Change: 1960-01-02 09:01:00.000298240 +0800
 Birth: 1960-01-02 09:01:00.000298240 +0800

uucore: time: Add options for format_system_time

Depending on the caller, we want the number of seconds, that
and an error printed out, or seconds+nanoseconds.

stat: Stop relying on fsext::Birth

We can rely on other fsext/time functions, and stay a bit more
consistent.

stat: Use uucore::time:format_system_time function

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

drinkcat added 4 commits July 28, 2025 21:16
We can rely on other fsext/time functions, and stay a bit more
consistent.
Depending on the caller, we want the number of seconds, that
and an error printed out, or seconds+nanoseconds.
Useful for archaeologists and time travellers, do not crash if
ctime is before 1970.

Creating a file with such a change time is a bit challenging
(touch can't change that), so we can't easily add end-to-end
tests.

Steps to create a filesystem with a file `x` with birth/change
time in 1960.
```
dd if=/dev/zero bs=100M count=0 seek=1 of=ext4
mkfs.ext4 ext4
sudo mount ext4 mnt
touch mnt/x
umount mnt
echo "set_inode_field x ctime 196001010101" | debugfs -w ext4
echo "set_inode_field x ctime_extra 1234" | debugfs -w ext4
echo "set_inode_field x crtime 196001010101" | debugfs -w ext4
echo "set_inode_field x crtime_extra 0x123400" | debugfs -w ext4
sudo mount ext4 mnt
```

$ cargo run -p uu_stat mnt/x
  File: mnt/x
  size: 0         	Blocks: 0          IO Block: 1024   regular empty file
Device: 700h/1792d	Inode: 13          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2025-07-26 19:52:00.849821694 +0800
Modify: 2025-07-26 19:52:00.849821694 +0800
Change: 1960-01-02 09:01:00.000298240 +0800
 Birth: 1960-01-02 09:01:00.000298240 +0800
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

@sylvestre sylvestre merged commit e48c4a7 into uutils:main Jul 30, 2025
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants