Commit 8428291
committed
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 +08001 parent 6c73ef6 commit 8428291
1 file changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
147 | 159 | | |
148 | 160 | | |
149 | 161 | | |
| |||
0 commit comments