nix icon indicating copy to clipboard operation
nix copied to clipboard

Add wrappers for the stat*64 functions

Open ixeft opened this issue 7 years ago • 7 comments

Hello,

I'm not a rust programmer, but trying to compile https://github.com/greshake/i3status-rust and particularly this file : https://github.com/greshake/i3status-rust/blob/master/src/blocks/disk_space.rs I noticed that Statvfs::b_fsize where u32 instead of u64 creating a compilation error

using "as u64" I got the code compiling but now, with path bigger than 4Gio, I got an overflow getting wrong value of statvfs.f_bfree / statvfs.f_bsize (crazy big values)

Exemple of code that should demontrate the bug with 32bit system (Archlinux i686 - Intel Atom Z520)

extern crate nix;
use self::nix::sys::statvfs::vfs::Statvfs;
let statvfs = Statvfs::for_path(Path::new("a/path/with/size/bigger/than/4Gio"))

Using glibc in C/C++ I would define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE to solve this problem. not sure how to do so here.

Regards,

ixeft avatar Aug 24 '17 06:08 ixeft

We just wrap the statvfs strict provided by libc. This is likely an issue with the type as it's declared there. Please open and issue there to discuss this and link back to this one.

Susurrus avatar Aug 24 '17 06:08 Susurrus

yes, libc provide a flag to modify the type of those variable and allowing usage of more than 2Gio files (not 4Gio as I mentioned) by setting

#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

or even better :

#define _FILE_OFFSET_BITS

http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

ixeft avatar Aug 24 '17 06:08 ixeft

Ok, I just realized you wanted me to report a bug in i3status-rust, not in glibc :)

I just did that https://github.com/greshake/i3status-rust/issues/88

Thanks

ixeft avatar Aug 24 '17 06:08 ixeft

Actually, susurrus meant that you should report a bug to Rust's libc, here: https://github.com/rust-lang/libc . That crate defines the FFI wrappers for all standard C structures.

asomers avatar Aug 24 '17 14:08 asomers

I believe the solution here is to expose the stat*64 functions. for i3status to consume. I've therefore retitled this issue accordingly.

Susurrus avatar Aug 26 '17 17:08 Susurrus

I'd love to have a safe wrapper for statvfs64. Should I open a fresh issue (or PR) for that?

joshtriplett avatar Jun 06 '21 04:06 joshtriplett

Sure. If you're motivated, create a PR for it.

asomers avatar Jun 06 '21 04:06 asomers