mod.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //! statvfs implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstatvfs.h.html
  2. use c_str::CStr;
  3. use header::fcntl::O_PATH;
  4. use platform::types::*;
  5. use platform::{Pal, Sys};
  6. //pub const ST_RDONLY
  7. //pub const ST_NOSUID
  8. #[repr(C)]
  9. #[derive(Default)]
  10. pub struct statvfs {
  11. pub f_bsize: c_ulong,
  12. pub f_frsize: c_ulong,
  13. pub f_blocks: fsblkcnt_t,
  14. pub f_bfree: fsblkcnt_t,
  15. pub f_bavail: fsblkcnt_t,
  16. pub f_files: fsfilcnt_t,
  17. pub f_ffree: fsfilcnt_t,
  18. pub f_favail: fsfilcnt_t,
  19. pub f_fsid: c_ulong,
  20. pub f_flag: c_ulong,
  21. pub f_namemax: c_ulong,
  22. }
  23. #[no_mangle]
  24. pub extern "C" fn fstatvfs(fildes: c_int, buf: *mut statvfs) -> c_int {
  25. Sys::fstatvfs(fildes, buf)
  26. }
  27. #[no_mangle]
  28. pub unsafe extern "C" fn statvfs(file: *const c_char, buf: *mut statvfs) -> c_int {
  29. let file = CStr::from_ptr(file);
  30. let fd = Sys::open(file, O_PATH, 0);
  31. if fd < 0 {
  32. return -1;
  33. }
  34. let res = Sys::fstatvfs(fd, buf);
  35. Sys::close(fd);
  36. res
  37. }