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

Disk Space readout reporting wrong disk size #325

Open
0323pin opened this issue Sep 12, 2024 · 9 comments
Open

Disk Space readout reporting wrong disk size #325

0323pin opened this issue Sep 12, 2024 · 9 comments
Labels
platform/netbsd type/bug Something isn't working.

Comments

@0323pin
Copy link
Contributor

0323pin commented Sep 12, 2024

Describe the bug
Disk Space readout reporting wrong disk size.

To Reproduce
Config macchina to display DiskSpace.

Expected behavior
Should report the correct values.

Screenshots
2024-09-12-064734_722x381_scrot

Output of df -h:

Filesystem     Size   Used  Avail %Cap Mounted on
/dev/wd0a      394G   9.1G   365G   2% /
tmpfs          2.4G    16K   2.4G   0% /tmp
kernfs         1.0K   1.0K     0B 100% /kern
ptyfs          1.0K   1.0K     0B 100% /dev/pts
procfs         4.0K   4.0K     0B 100% /proc
tmpfs          2.4G   7.4M   2.4G   0% /var/shm

macchina --doctor output

We've collected a total of 12 readouts including 0 failed read(s) and 0 read(s) resulting in a warning.

🎉 You are good to go! No failures detected.

System Information

  • Distribution: NA
  • Desktop Environment: None
  • Operating System: NetBSD
  • Terminal: Alacritty
  • Macchina's version: 6.2.0
@grtcdr grtcdr added the type/bug Something isn't working. label Sep 12, 2024
@grtcdr
Copy link
Member

grtcdr commented Sep 13, 2024

I also see wrong information but it's much lower than the expected value on my side.

I'd love to know if @Rolv-Apneseth could pursue his ideas in #286, the feature discussed in that ticket is really essential for the disk usage readout.

@Rolv-Apneseth
Copy link
Contributor

Hey! Been a while but yes I'd be happy to look into it. I did go off on a dev branch on my fork for my own personal use but I'll have a go at making a PR when I get some time

@grtcdr
Copy link
Member

grtcdr commented Sep 14, 2024

Wonderful, thanks for chiming in!

@Rolv-Apneseth
Copy link
Contributor

Rolv-Apneseth commented Sep 16, 2024

In relation to this issue, I have no idea where such a wildly inaccurate value is coming from, though the NetBSD code for reading used/total bytes does seem to differ a bit from the *nix code.

Just as a side note, df -h gives the values in powers of 1024 but I believe macchina uses the SI units, so powers of 1000. df --si should be more accurate if that is the case, which it is for me.

@0323pin
Copy link
Contributor Author

0323pin commented Sep 16, 2024

Just as a side note, df -h gives the values in powers of 1024 but I believe macchina uses the SI units, so powers of 1000. df --si should be more accurate if that is the case, which it is for me.

Believe me, I know the difference between SI and other widely accepted units but, this is seriously wrong. I have a 365 Gb SSD being reported as 3.4 Tb

df -si doesn't exist on NetBSD but, I can give you df -g,

~> df -g
Filesystem   1G-blocks      Used     Avail %Cap Mounted on
/dev/wd0a          394         9       365   2% /
tmpfs                2         0         2   0% /tmp
kernfs               0         0         0 100% /kern
ptyfs                0         0         0 100% /dev/pts
procfs               0         0         0 100% /proc
tmpfs                2         0         2   0% /var/shm

and perhaps man df(1)

@Rolv-Apneseth
Copy link
Contributor

I assumed you did yes, sorry, was just mentioning in case someone searches this issue in the future for differences which might be accounted for by the units.

Didn't realise that df would be different on NetBSD, the more you know. But from that man page I can see they just don't have the long form, df -H should be the same on both. Irrelevant here anyway, like you said the issue is much bigger than that.

@grtcdr
Copy link
Member

grtcdr commented Sep 16, 2024

I think I know what's going on.

Rust's libc does not have any bindings for NetBSD's statfs syscall (https://man.netbsd.org/NetBSD-1.6/statfs.2), this can be confirmed both from the documentation of the libc crate 1 and filtering for the statfs keyword in the crate's source code 2.

I'm really disappointed that I didn't catch this discrepancy before porting the code. I suppose this is why @0323pin is getting "garbage" output in his disk space readout.

Footnotes

  1. https://docs.rs/libc/latest/x86_64-unknown-netbsd/libc/index.html

  2. https://github.com/rust-lang/libc/blob/main/src/unix/bsd/netbsdlike/netbsd/mod.rs

@0323pin
Copy link
Contributor Author

0323pin commented Sep 17, 2024

Rust's libc does not have any bindings for NetBSD's statfs syscall

That's because statfs is a deprecated syscall that has been replaced by statvfs on NetBSD in 2005, see statvfs(2).

Note: other OSs might still use statfs, I know that FreeBSD and DragonFly BSD do but, on NetBSD it has been removed.

statvfs is supported, I've added this to libc about a year ago to fix issues with the trash-rs crate.

@grtcdr
Copy link
Member

grtcdr commented Sep 17, 2024

Alright, I'll write a working port this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/netbsd type/bug Something isn't working.
Development

No branches or pull requests

3 participants