Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android 64-bit compatibility adaptions #5821

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl AddAssign for Row {
let bytes = self.bytes + rhs.bytes;
let bytes_used = self.bytes_used + rhs.bytes_used;
let bytes_avail = self.bytes_avail + rhs.bytes_avail;
let inodes = self.inodes + rhs.inodes;
let inodes_used = self.inodes_used + rhs.inodes_used;
let inodes = self.inodes.saturating_add(rhs.inodes);
let inodes_used = self.inodes_used.saturating_add(rhs.inodes_used);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really have sometimes a number of inodes greater than u64::MAX?

If this is the case, is it ok to compute a wrong value by saturating the addition?

Copy link
Contributor Author

@cre4ture cre4ture Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this peace of code does an accumulation. As far as I understood the code, this accumulation is purely needed to compute an optional finalising row called "total" in the output. This "total" row shall display the sum of each column. Thus, also the inodes are accumulated.

On my phones system, there are apparently several filesystems that reports "inodes" as exactly u64::MAX. Summing that up always causes an int 64 overflow. But is it relevant? I guess not really as the number is anyway insanely high. If someone finds a usecase where this is relevant, we can still extend the integer type to u128.
Alternatively. one could automatically filter the filesystem with u64::MAX because the number might anyway not be valid.
EDIT: One addition could be that we don't print the value in the total row when it is at u64::MAX because the sum is invalid. That might be the easiest and also correct behavior as long as we don't extent to u128.
EDIT2: The feature to compute the "total" row is apparently not available in the df implementation on my phone (toybox 0.8.4-android)

Output of pre-installed (toybox, NOT GNU) of df on my phone:

~/rust/coreutils $ df -i
Filesystem                                           Inodes  IUsed                IFree IUse% Mounted on
/dev/block/dm-15                       18446744073709551615   3141 18446744073709548474    1% /
tmpfs                                               1457181   1464              1455717    1% /dev
tmpfs                                               1457181     65              1457116    1% /mnt
/dev/block/dm-16                       18446744073709551615   3002 18446744073709548613    1% /system_ext
/dev/block/dm-17                                        304    298                    6   99% /product
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/app
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/priv-app
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/lib64
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/lib
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/overlay
overlay                                18446744073709551615      0 18446744073709551615    0% /product/etc/permissions
overlay                                18446744073709551615      0 18446744073709551615    0% /product/framework
/dev/block/dm-18                       18446744073709551615      0 18446744073709551615    0% /vendor
/dev/block/dm-19                       18446744073709551615      0 18446744073709551615    0% /odm
/dev/block/dm-20                       18446744073709551615      0 18446744073709551615    0% /my_product
/dev/block/dm-21                       18446744073709551615      0 18446744073709551615    0% /my_engineering
/dev/block/dm-23                       18446744073709551615      0 18446744073709551615    0% /my_carrier
/dev/block/dm-24                       18446744073709551615      0 18446744073709551615    0% /my_region
/dev/block/dm-25                       18446744073709551615      0 18446744073709551615    0% /my_heytap
/dev/block/dm-26                       18446744073709551615      0 18446744073709551615    0% /my_stock
/dev/block/dm-27                       18446744073709551615      0 18446744073709551615    0% /my_preload
/dev/block/dm-28                       18446744073709551615      0 18446744073709551615    0% /my_bigball
/dev/block/dm-29                       18446744073709551615      0 18446744073709551615    0% /my_manifest
tmpfs                                               1457181     99              1457082    1% /apex
/dev/block/loop7                                         48     35                   13   73% /apex/com.android.i18n@1
/dev/block/loop8                                         32     29                    3   91% /apex/com.android.wifi@319999900
/dev/block/loop5                                         32     20                   12   63% /apex/com.android.apex.cts.shim@1
/dev/block/loop6                                         32     23                    9   72% /apex/com.android.appsearch@300000000
/dev/block/loop11                                       304    290                   14   96% /apex/com.android.vndk.v31@1
/dev/block/dm-30                                         32     25                    7   79% /apex/com.android.extservices@341131030
/dev/block/dm-32                                         32     28                    4   88% /apex/com.android.permission@341110010
/dev/block/loop15                                        64     50                   14   79% /apex/com.android.runtime@1
/dev/block/dm-33                                        176    167                    9   95% /apex/com.android.conscrypt@341110002
/dev/block/dm-31                                        112    112                    0  100% /apex/com.android.art@341110062
/dev/block/loop16                                       608    596                   12   99% /apex/com.android.vndk.v30@1
/dev/block/dm-34                                         32     20                   12   63% /apex/com.android.tzdata@313110000
/dev/block/dm-35                                         32     20                   12   63% /apex/com.android.scheduling@340819220
/dev/block/dm-36                                         32     31                    1   97% /apex/com.android.os.statsd@341114000
/dev/block/dm-37                                         64     58                    6   91% /apex/com.android.media@341111002
/dev/block/dm-38                                         32     27                    5   85% /apex/com.android.mediaprovider@341111020
/dev/block/dm-39                                         48     36                   12   75% /apex/com.android.adbd@340912202
/dev/block/dm-40                                        128    114                   14   90% /apex/com.android.media.swcodec@341111002
/dev/block/dm-42                                         32     21                   11   66% /apex/com.android.cellbroadcast@341110000
/dev/block/dm-41                                         16     16                    0  100% /apex/com.android.neuralnetworks@341010000
/dev/block/loop27                                        32     26                    6   82% /apex/com.google.mainline.primary.libs@331059000
/dev/block/dm-43                                         32     20                   12   63% /apex/com.android.ipsec@340914200
/dev/block/dm-44                                         80     66                   14   83% /apex/com.android.tethering@341112070
/dev/block/dm-45                                         80     75                    5   94% /apex/com.google.mainline.primary.libs@341177000
/dev/block/dm-46                                         16     16                    0  100% /apex/com.android.resolv@341110000
/dev/block/dm-47                                         32     24                    8   75% /apex/com.android.sdkext@341110000
/dev/block/bootdevice/by-name/cache                  114688     55               114633    1% /cache
/dev/block/bootdevice/by-name/userdata             12812797 348578             12464219    3% /data
/dev/fuse                                          12812797 348578             12464219    3% /storage/emulated
/data/media                                        12812797 348578             12464219    3% /storage/emulated/0/Android/data
~/rust/coreutils $ 

for completion the output of uutils:

~/rust/coreutils $ target/debug/coreutils df -i --total
Filesystem                                           Inodes  IUsed                IFree IUse% Mounted on
/dev/block/dm-15                       18446744073709551615   3141 18446744073709548474    1% /
tmpfs                                               1457181   1464              1455717    1% /dev
tmpfs                                               1457181     65              1457116    1% /mnt
/dev/block/by-name/metadata                            4096     31                 4065    1% /metadata
/dev/block/dm-16                       18446744073709551615   3002 18446744073709548613    1% /system_ext
/dev/block/dm-17                                        304    298                    6   99% /product
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/app
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/priv-app
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/lib64
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/lib
overlay-overlay                        18446744073709551615      0 18446744073709551615    0% /product/overlay
overlay                                18446744073709551615      0 18446744073709551615    0% /product/etc/permissions
overlay                                18446744073709551615      0 18446744073709551615    0% /product/framework
/dev/block/dm-18                       18446744073709551615      0 18446744073709551615    0% /vendor
/dev/block/dm-19                       18446744073709551615      0 18446744073709551615    0% /odm
/dev/block/dm-20                       18446744073709551615      0 18446744073709551615    0% /my_product
/dev/block/dm-21                       18446744073709551615      0 18446744073709551615    0% /my_engineering
/dev/block/dm-23                       18446744073709551615      0 18446744073709551615    0% /my_carrier
/dev/block/dm-24                       18446744073709551615      0 18446744073709551615    0% /my_region
/dev/block/dm-25                       18446744073709551615      0 18446744073709551615    0% /my_heytap
/dev/block/dm-26                       18446744073709551615      0 18446744073709551615    0% /my_stock
/dev/block/dm-27                       18446744073709551615      0 18446744073709551615    0% /my_preload
/dev/block/dm-28                       18446744073709551615      0 18446744073709551615    0% /my_bigball
/dev/block/dm-29                       18446744073709551615      0 18446744073709551615    0% /my_manifest
tmpfs                                               1457181     99              1457082    1% /apex
/dev/block/loop7                                         48     35                   13   73% /apex/com.android.i18n@1
/dev/block/loop7                                         48     35                   13   73% /apex/com.android.i18n
/dev/block/loop8                                         32     29                    3   91% /apex/com.android.wifi@319999900
/dev/block/loop5                                         32     20                   12   63% /apex/com.android.apex.cts.shim@1
/dev/block/loop8                                         32     29                    3   91% /apex/com.android.wifi
/dev/block/loop6                                         32     23                    9   72% /apex/com.android.appsearch@300000000
/dev/block/loop6                                         32     23                    9   72% /apex/com.android.appsearch
/dev/block/loop5                                         32     20                   12   63% /apex/com.android.apex.cts.shim
/dev/block/loop11                                       304    290                   14   96% /apex/com.android.vndk.v31@1
/dev/block/loop11                                       304    290                   14   96% /apex/com.android.vndk.v31
/dev/block/dm-30                                         32     25                    7   79% /apex/com.android.extservices@341131030
/dev/block/dm-30                                         32     25                    7   79% /apex/com.android.extservices
/dev/block/dm-32                                         32     28                    4   88% /apex/com.android.permission@341110010
/dev/block/dm-32                                         32     28                    4   88% /apex/com.android.permission
/dev/block/loop15                                        64     50                   14   79% /apex/com.android.runtime@1
/dev/block/loop15                                        64     50                   14   79% /apex/com.android.runtime
/dev/block/dm-33                                        176    167                    9   95% /apex/com.android.conscrypt@341110002
/dev/block/dm-31                                        112    112                    0  100% /apex/com.android.art@341110062
/dev/block/dm-33                                        176    167                    9   95% /apex/com.android.conscrypt
/dev/block/dm-31                                        112    112                    0  100% /apex/com.android.art
/dev/block/loop16                                       608    596                   12   99% /apex/com.android.vndk.v30@1
/dev/block/loop16                                       608    596                   12   99% /apex/com.android.vndk.v30
/dev/block/dm-34                                         32     20                   12   63% /apex/com.android.tzdata@313110000
/dev/block/dm-34                                         32     20                   12   63% /apex/com.android.tzdata
/dev/block/dm-35                                         32     20                   12   63% /apex/com.android.scheduling@340819220
/dev/block/dm-35                                         32     20                   12   63% /apex/com.android.scheduling
/dev/block/dm-36                                         32     31                    1   97% /apex/com.android.os.statsd@341114000
/dev/block/dm-36                                         32     31                    1   97% /apex/com.android.os.statsd
/dev/block/dm-37                                         64     58                    6   91% /apex/com.android.media@341111002
/dev/block/dm-37                                         64     58                    6   91% /apex/com.android.media
/dev/block/dm-38                                         32     27                    5   85% /apex/com.android.mediaprovider@341111020
/dev/block/dm-38                                         32     27                    5   85% /apex/com.android.mediaprovider
/dev/block/dm-39                                         48     36                   12   75% /apex/com.android.adbd@340912202
/dev/block/dm-39                                         48     36                   12   75% /apex/com.android.adbd
/dev/block/dm-40                                        128    114                   14   90% /apex/com.android.media.swcodec@341111002
/dev/block/dm-40                                        128    114                   14   90% /apex/com.android.media.swcodec
/dev/block/dm-42                                         32     21                   11   66% /apex/com.android.cellbroadcast@341110000
/dev/block/dm-41                                         16     16                    0  100% /apex/com.android.neuralnetworks@341010000
/dev/block/dm-41                                         16     16                    0  100% /apex/com.android.neuralnetworks
/dev/block/dm-42                                         32     21                   11   66% /apex/com.android.cellbroadcast
/dev/block/loop27                                        32     26                    6   82% /apex/com.google.mainline.primary.libs@331059000
/dev/block/dm-43                                         32     20                   12   63% /apex/com.android.ipsec@340914200
/dev/block/dm-43                                         32     20                   12   63% /apex/com.android.ipsec
/dev/block/dm-44                                         80     66                   14   83% /apex/com.android.tethering@341112070
/dev/block/dm-44                                         80     66                   14   83% /apex/com.android.tethering
/dev/block/dm-45                                         80     75                    5   94% /apex/com.google.mainline.primary.libs@341177000
/dev/block/dm-46                                         16     16                    0  100% /apex/com.android.resolv@341110000
/dev/block/dm-46                                         16     16                    0  100% /apex/com.android.resolv
/dev/block/dm-47                                         32     24                    8   75% /apex/com.android.sdkext@341110000
/dev/block/dm-47                                         32     24                    8   75% /apex/com.android.sdkext
/dev/block/bootdevice/by-name/cache                  114688     55               114633    1% /cache
/dev/block/bootdevice/by-name/userdata             12812797 348591             12464206    3% /data
/dev/fuse                                          12812797 348591             12464206    3% /storage/emulated
/data/media                                        12812797 348591             12464206    3% /storage/emulated/0/Android/data
/data/media                                        12812797 348591             12464206    3% /storage/emulated/0/Android/obb
total                                  18446744073709551615 1406308 18446744073709551615    1% -
~/rust/coreutils $ 

filesystem types:

~/rust/coreutils $ target/debug/coreutils df --output=source,fstype,target,itotal,iused,iavail,ipcent
Filesystem                             Type     Mounted on                                                     Inodes  IUsed                IFree IUse%
/dev/block/dm-15                       erofs    /                                                18446744073709551615   3141 18446744073709548474    1%
tmpfs                                  tmpfs    /dev                                                          1457181   1464              1455717    1%
tmpfs                                  tmpfs    /mnt                                                          1457181     65              1457116    1%
/dev/block/by-name/metadata            ext4     /metadata                                                        4096     31                 4065    1%
/dev/block/dm-16                       erofs    /system_ext                                      18446744073709551615   3002 18446744073709548613    1%
/dev/block/dm-17                       ext4     /product                                                          304    298                    6   99%
overlay-overlay                        overlay  /product/app                                     18446744073709551615      0 18446744073709551615    0%
overlay-overlay                        overlay  /product/priv-app                                18446744073709551615      0 18446744073709551615    0%
overlay-overlay                        overlay  /product/lib64                                   18446744073709551615      0 18446744073709551615    0%
overlay-overlay                        overlay  /product/lib                                     18446744073709551615      0 18446744073709551615    0%
overlay-overlay                        overlay  /product/overlay                                 18446744073709551615      0 18446744073709551615    0%
overlay                                overlay  /product/etc/permissions                         18446744073709551615      0 18446744073709551615    0%
overlay                                overlay  /product/framework                               18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-18                       erofs    /vendor                                          18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-19                       erofs    /odm                                             18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-20                       erofs    /my_product                                      18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-21                       erofs    /my_engineering                                  18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-23                       erofs    /my_carrier                                      18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-24                       erofs    /my_region                                       18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-25                       erofs    /my_heytap                                       18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-26                       erofs    /my_stock                                        18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-27                       erofs    /my_preload                                      18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-28                       erofs    /my_bigball                                      18446744073709551615      0 18446744073709551615    0%
/dev/block/dm-29                       erofs    /my_manifest                                     18446744073709551615      0 18446744073709551615    0%
tmpfs                                  tmpfs    /apex                                                         1457181     99              1457082    1%
/dev/block/loop7                       ext4     /apex/com.android.i18n@1                                           48     35                   13   73%
/dev/block/loop7                       ext4     /apex/com.android.i18n                                             48     35                   13   73%
/dev/block/loop8                       ext4     /apex/com.android.wifi@319999900                                   32     29                    3   91%
/dev/block/loop5                       ext4     /apex/com.android.apex.cts.shim@1                                  32     20                   12   63%
/dev/block/loop8                       ext4     /apex/com.android.wifi                                             32     29                    3   91%
/dev/block/loop6                       ext4     /apex/com.android.appsearch@300000000                              32     23                    9   72%
/dev/block/loop6                       ext4     /apex/com.android.appsearch                                        32     23                    9   72%
/dev/block/loop5                       ext4     /apex/com.android.apex.cts.shim                                    32     20                   12   63%
/dev/block/loop11                      ext4     /apex/com.android.vndk.v31@1                                      304    290                   14   96%
/dev/block/loop11                      ext4     /apex/com.android.vndk.v31                                        304    290                   14   96%
/dev/block/dm-30                       ext4     /apex/com.android.extservices@341131030                            32     25                    7   79%
/dev/block/dm-30                       ext4     /apex/com.android.extservices                                      32     25                    7   79%
/dev/block/dm-32                       ext4     /apex/com.android.permission@341110010                             32     28                    4   88%
/dev/block/dm-32                       ext4     /apex/com.android.permission                                       32     28                    4   88%
/dev/block/loop15                      ext4     /apex/com.android.runtime@1                                        64     50                   14   79%
/dev/block/loop15                      ext4     /apex/com.android.runtime                                          64     50                   14   79%
/dev/block/dm-33                       ext4     /apex/com.android.conscrypt@341110002                             176    167                    9   95%
/dev/block/dm-31                       ext4     /apex/com.android.art@341110062                                   112    112                    0  100%
/dev/block/dm-33                       ext4     /apex/com.android.conscrypt                                       176    167                    9   95%
/dev/block/dm-31                       ext4     /apex/com.android.art                                             112    112                    0  100%
/dev/block/loop16                      ext4     /apex/com.android.vndk.v30@1                                      608    596                   12   99%
/dev/block/loop16                      ext4     /apex/com.android.vndk.v30                                        608    596                   12   99%
/dev/block/dm-34                       ext4     /apex/com.android.tzdata@313110000                                 32     20                   12   63%
/dev/block/dm-34                       ext4     /apex/com.android.tzdata                                           32     20                   12   63%
/dev/block/dm-35                       ext4     /apex/com.android.scheduling@340819220                             32     20                   12   63%
/dev/block/dm-35                       ext4     /apex/com.android.scheduling                                       32     20                   12   63%
/dev/block/dm-36                       ext4     /apex/com.android.os.statsd@341114000                              32     31                    1   97%
/dev/block/dm-36                       ext4     /apex/com.android.os.statsd                                        32     31                    1   97%
/dev/block/dm-37                       ext4     /apex/com.android.media@341111002                                  64     58                    6   91%
/dev/block/dm-37                       ext4     /apex/com.android.media                                            64     58                    6   91%
/dev/block/dm-38                       ext4     /apex/com.android.mediaprovider@341111020                          32     27                    5   85%
/dev/block/dm-38                       ext4     /apex/com.android.mediaprovider                                    32     27                    5   85%
/dev/block/dm-39                       ext4     /apex/com.android.adbd@340912202                                   48     36                   12   75%
/dev/block/dm-39                       ext4     /apex/com.android.adbd                                             48     36                   12   75%
/dev/block/dm-40                       ext4     /apex/com.android.media.swcodec@341111002                         128    114                   14   90%
/dev/block/dm-40                       ext4     /apex/com.android.media.swcodec                                   128    114                   14   90%
/dev/block/dm-42                       ext4     /apex/com.android.cellbroadcast@341110000                          32     21                   11   66%
/dev/block/dm-41                       ext4     /apex/com.android.neuralnetworks@341010000                         16     16                    0  100%
/dev/block/dm-41                       ext4     /apex/com.android.neuralnetworks                                   16     16                    0  100%
/dev/block/dm-42                       ext4     /apex/com.android.cellbroadcast                                    32     21                   11   66%
/dev/block/loop27                      ext4     /apex/com.google.mainline.primary.libs@331059000                   32     26                    6   82%
/dev/block/dm-43                       ext4     /apex/com.android.ipsec@340914200                                  32     20                   12   63%
/dev/block/dm-43                       ext4     /apex/com.android.ipsec                                            32     20                   12   63%
/dev/block/dm-44                       ext4     /apex/com.android.tethering@341112070                              80     66                   14   83%
/dev/block/dm-44                       ext4     /apex/com.android.tethering                                        80     66                   14   83%
/dev/block/dm-45                       ext4     /apex/com.google.mainline.primary.libs@341177000                   80     75                    5   94%
/dev/block/dm-46                       ext4     /apex/com.android.resolv@341110000                                 16     16                    0  100%
/dev/block/dm-46                       ext4     /apex/com.android.resolv                                           16     16                    0  100%
/dev/block/dm-47                       ext4     /apex/com.android.sdkext@341110000                                 32     24                    8   75%
/dev/block/dm-47                       ext4     /apex/com.android.sdkext                                           32     24                    8   75%
/dev/block/bootdevice/by-name/cache    ext4     /cache                                                         114688     55               114633    1%
/dev/block/bootdevice/by-name/userdata f2fs     /data                                                        12812797 348595             12464202    3%
/dev/fuse                              fuse     /storage/emulated                                            12812797 348595             12464202    3%
/data/media                            sdcardfs /storage/emulated/0/Android/data                             12812797 348595             12464202    3%
/data/media                            sdcardfs /storage/emulated/0/Android/obb                              12812797 348595             12464202    3%
~/rust/coreutils $ 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awfully similar to a -1 cast to uint64_t

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you retry with --total as well? That would be interesting to see how GNU coreutils perform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some editing to give more detail. So please read again. The df-variant that runs on my phone is "toybox" and not GNU. It doesn't support the "--total" argument.

Copy link
Contributor Author

@cre4ture cre4ture Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a small image for erofs on my ubuntu PC. Then you can see the GNU output:

uli@hp13-ulix:~$ df --total --output='source','fstype','itotal','iused','iavail','ipcent','size','used','avail','pcent','file','target'
Filesystem     Type       Inodes   IUsed                IFree IUse% 1K-blocks      Used     Avail Use% File Mounted on
tmpfs          tmpfs     2016003    1405              2014598    1%   1612804      2280   1610524   1% -    /run
/dev/nvme0n1p6 ext4      6111232  621990              5489242   11%  95535524  33714300  56922052  38% -    /
tmpfs          tmpfs     2016003      71              2015932    1%   8064012     19696   8044316   1% -    /dev/shm
tmpfs          tmpfs     2016003       4              2015999    1%      5120         4      5116   1% -    /run/lock
efivarfs       efivarfs        0       0                    0     -       192       127        61  68% -    /sys/firmware/efi/efivars
/dev/nvme0n1p7 ext4      9895936  740739              9155197    8% 154706320 122316404  24458476  84% -    /home
/dev/nvme0n1p1 vfat            0       0                    0     -    262144     89720    172424  35% -    /boot/efi
tmpfs          tmpfs      403200     202               402998    1%   1612800       168   1612632   1% -    /run/user/1000
/dev/nvme0n1p5 ntfs3           0       0                    0     - 512032764 370522632 141510132  73% -    /media/uli/WData
/dev/loop27    erofs           -       - 18446744073709551613     -         4         4         0 100% -    /media/uli/486ad2a2-6303-4504-87ff-5176e55b2239
total          -        22458377 1364414             21093963    7% 773831684 526665335 234335733  70% -    -
uli@hp13-ulix:~$ 

its placing some dashes "-" and EDIT: its having a silent integer-overlfow for the IFree. I checked it, the real sum without "erofs" would be "21093966" and not "21093963" ... thats 3 off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, the inodes for erofs are not really relevant in general as it is a read only filesystem

Copy link
Contributor Author

@cre4ture cre4ture Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My test on Ubuntu prooves that the issue with the integeroverflow is actually also visible on non-android systems if they use erofs. So we could actually split this change into an own pull-request.

li@hp13-ulix:~$ dev_rust/coreutils/target/debug/coreutils df --total --output='source','fstype','itotal','iused','iavail','ipcent','size','used','avail','pcent','file','target'
thread 'main' panicked at src/uu/df/src/table.rs:105:22:
attempt to add with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
uli@hp13-ulix:~$ 

*self = Self {
file: None,
fs_device: "total".into(),
Expand All @@ -125,7 +125,7 @@ impl AddAssign for Row {
bytes_capacity: None,
inodes,
inodes_used,
inodes_free: self.inodes_free + rhs.inodes_free,
inodes_free: self.inodes_free.saturating_add(rhs.inodes_free),
inodes_usage: if inodes == 0 {
None
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl FsMeta for StatFs {
not(target_arch = "s390x"),
target_pointer_width = "64"
))]
return self.f_bsize;
return self.f_bsize; // i64 -> i64 - OK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure those comments are needed, the Rust compiler is here to tell us if this is ok or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it there to help the reviewer/developer that reads this code to understand what happens. There are a lot of #[cfg(..)] around there and its not directly visible what the main point in the three cases is. But I'll remove it if you insist on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just expressing a preference, I'll let the coreutils maintainers weight on this.

cre4ture marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(all(
not(target_env = "musl"),
not(target_os = "freebsd"),
Expand All @@ -655,7 +655,7 @@ impl FsMeta for StatFs {
not(target_pointer_width = "64")
)
))]
return self.f_bsize.into();
return self.f_bsize.into(); // i32 or u32 -> i64 - OK
cre4ture marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(any(
target_env = "musl",
target_os = "freebsd",
Expand All @@ -664,7 +664,7 @@ impl FsMeta for StatFs {
target_os = "redox",
all(target_os = "android", target_pointer_width = "64"),
))]
return self.f_bsize.try_into().unwrap();
return self.f_bsize.try_into().unwrap(); // u64 -> i64 - might fail if number is too high
cre4ture marked this conversation as resolved.
Show resolved Hide resolved
}
fn total_blocks(&self) -> u64 {
#[cfg(target_pointer_width = "64")]
Expand Down
13 changes: 9 additions & 4 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,18 @@ fn test_type_option() {
#[test]
#[cfg(not(any(target_os = "freebsd", target_os = "windows")))] // FIXME: fix test for FreeBSD & Win
fn test_type_option_with_file() {
let fs_type = new_ucmd!()
let fs_type_cwd = new_ucmd!()
.args(&["--output=fstype", "."])
.succeeds()
.stdout_move_str();
let fs_type = fs_type.lines().nth(1).unwrap().trim();
let fs_type_cwd = fs_type_cwd.lines().nth(1).unwrap().trim();
let fs_type_root_dir = new_ucmd!()
.args(&["--output=fstype", "/"])
.succeeds()
.stdout_move_str();
let fs_type_root_dir = fs_type_root_dir.lines().nth(1).unwrap().trim();

new_ucmd!().args(&["-t", fs_type, "."]).succeeds();
new_ucmd!().args(&["-t", fs_type_cwd, "."]).succeeds();
new_ucmd!()
.args(&["-t", "nonexisting", "."])
.fails()
Expand All @@ -283,7 +288,7 @@ fn test_type_option_with_file() {
let fs_types: Vec<_> = fs_types
.lines()
.skip(1)
.filter(|t| t.trim() != fs_type && t.trim() != "")
.filter(|t| t.trim() != fs_type_cwd && t.trim() != fs_type_root_dir && t.trim() != "")
.collect();

if !fs_types.is_empty() {
Expand Down
43 changes: 27 additions & 16 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,24 @@ fn test_ls_allocation_size() {
.succeeds()
.stdout_matches(&Regex::new("[^ ] 2 [^ ]").unwrap());

#[cfg(all(
not(target_os = "freebsd"),
not(all(target_os = "android", target_pointer_width = "64"))
))]
let (zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) =
(4096, 1024, 8192, "4.0M");

#[cfg(all(target_os = "android", target_pointer_width = "64"))]
let (zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) =
(4100, 1025, 8200, "4.1M"); // FIXME: Investigate where this difference comes from. Is it OS or filesystem?

#[cfg(not(target_os = "freebsd"))]
scene
.ucmd()
.arg("-s1")
.arg("some-dir1")
.succeeds()
.stdout_is("total 4096\n 0 empty-file\n 0 file-with-holes\n4096 zero-file\n");
.stdout_is(format!("total {zero_file_size_4k}\n 0 empty-file\n 0 file-with-holes\n{zero_file_size_4k} zero-file\n"));

scene
.ucmd()
Expand All @@ -138,7 +149,7 @@ fn test_ls_allocation_size() {
.arg("some-dir1")
.succeeds()
.stdout_contains("0 empty-file")
.stdout_contains("4096 zero-file");
.stdout_contains(format!("{zero_file_size_4k} zero-file"));

// Test alignment of different block sized files
let res = scene.ucmd().arg("-si1").arg("some-dir1").succeeds();
Expand Down Expand Up @@ -185,10 +196,10 @@ fn test_ls_allocation_size() {
.arg("-s1")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 1024")
.stdout_contains(format!("total {zero_file_size_1k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("1024 zero-file");
.stdout_contains(format!("{zero_file_size_1k} zero-file"));

#[cfg(not(target_os = "freebsd"))]
scene
Expand All @@ -210,10 +221,10 @@ fn test_ls_allocation_size() {
.arg("-s1")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 1024")
.stdout_contains(format!("total {zero_file_size_1k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("1024 zero-file");
.stdout_contains(format!("{zero_file_size_1k} zero-file"));

#[cfg(not(target_os = "freebsd"))]
scene
Expand All @@ -222,10 +233,10 @@ fn test_ls_allocation_size() {
.arg("-s1")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 8192")
.stdout_contains(format!("total {zero_file_size_8k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("8192 zero-file");
.stdout_contains(format!("{zero_file_size_8k} zero-file"));

// -k should make 'ls' ignore the env var
#[cfg(not(target_os = "freebsd"))]
Expand All @@ -235,10 +246,10 @@ fn test_ls_allocation_size() {
.arg("-s1k")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 4096")
.stdout_contains(format!("total {zero_file_size_4k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("4096 zero-file");
.stdout_contains(format!("{zero_file_size_4k} zero-file"));

// but manually specified blocksize overrides -k
#[cfg(not(target_os = "freebsd"))]
Expand All @@ -248,10 +259,10 @@ fn test_ls_allocation_size() {
.arg("--block-size=4K")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 1024")
.stdout_contains(format!("total {zero_file_size_1k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("1024 zero-file");
.stdout_contains(format!("{zero_file_size_1k} zero-file"));

#[cfg(not(target_os = "freebsd"))]
scene
Expand All @@ -260,10 +271,10 @@ fn test_ls_allocation_size() {
.arg("--block-size=4K")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 1024")
.stdout_contains(format!("total {zero_file_size_1k}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("1024 zero-file");
.stdout_contains(format!("{zero_file_size_1k} zero-file"));

// si option should always trump the human-readable option
#[cfg(not(target_os = "freebsd"))]
Expand All @@ -285,10 +296,10 @@ fn test_ls_allocation_size() {
.arg("--block-size=human-readable")
.arg("some-dir1")
.succeeds()
.stdout_contains("total 4.0M")
.stdout_contains(format!("total {zero_file_size_4m}"))
.stdout_contains("0 empty-file")
.stdout_contains("0 file-with-holes")
.stdout_contains("4.0M zero-file");
.stdout_contains(format!("{zero_file_size_4m} zero-file"));

#[cfg(not(target_os = "freebsd"))]
scene
Expand Down
Loading