I am trying to use the c-like statfs
method from the nix
crate, which is declared like:
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut statfs) -> Result<()>
So, I understand that I have to create a libc::statfs struct and then pass a mutable pointer to it, so that statfs fills it with the correct values, something like:
let mut statfs_result = libc::statfs::default();
statfs::statfs("/", &mut statfs_result);
However, statfs has no new
or default
methods, so I can't create it this way. Also it has some private fields, so the following fails to compile as well, since f_spare and __val are private:
let mut statfs_result = libc::statfs {
f_type: 0,
f_bsize: 0,
f_blocks: 0,
f_bfree: 0,
f_bavail: 0,
f_files: 0,
f_ffree: 0,
f_fsid: libc::fsid_t {__val: [0, 0]},
f_namelen: 0,
f_frsize: 0,
f_spare: [0, 0, 0, 0, 0]
};
statfs::statfs("/", &mut statfs_result);
Is there a way to instantiate the struct and call the method, or is this problematic design with the library, making the method unusable?