You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #ifndef __STATVFS_UTIL_HPP__
  15. #define __STATVFS_UTIL_HPP__
  16. #include <string>
  17. #include <sys/statvfs.h>
  18. #include "success_fail.hpp"
  19. namespace StatVFS
  20. {
  21. static
  22. inline
  23. bool
  24. readonly(const struct statvfs &st)
  25. {
  26. return (st.f_flag & ST_RDONLY);
  27. }
  28. static
  29. inline
  30. uint64_t
  31. spaceavail(const struct statvfs &st)
  32. {
  33. return (st.f_frsize * st.f_bavail);
  34. }
  35. static
  36. inline
  37. uint64_t
  38. spaceused(const struct statvfs &st)
  39. {
  40. return (st.f_frsize * (st.f_blocks - st.f_bavail));
  41. }
  42. }
  43. #endif