1

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?

Joe Clay
  • 33,401
  • 4
  • 85
  • 85
thanasis2028
  • 125
  • 5
  • 1
    The duplicate's answer applied to this problem: `let mut statfs_result: libc::statfs = ::std::mem::zeroed();` – E_net4 May 22 '18 at 13:19

0 Answers0