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.

97 lines
2.0 KiB

  1. /*
  2. ISC License
  3. Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #include "branch.hpp"
  16. #include "ef.hpp"
  17. #include "errno.hpp"
  18. #include "num.hpp"
  19. Branch::Branch(const uint64_t &default_minfreespace_)
  20. : _default_minfreespace(&default_minfreespace_)
  21. {
  22. }
  23. int
  24. Branch::from_string(const std::string &str_)
  25. {
  26. return -EINVAL;
  27. }
  28. std::string
  29. Branch::to_string(void) const
  30. {
  31. std::string rv;
  32. rv = path;
  33. rv += '=';
  34. switch(mode)
  35. {
  36. default:
  37. case Branch::Mode::RW:
  38. rv += "RW";
  39. break;
  40. case Branch::Mode::RO:
  41. rv += "RO";
  42. break;
  43. case Branch::Mode::NC:
  44. rv += "NC";
  45. break;
  46. }
  47. if(_minfreespace.has_value())
  48. {
  49. rv += ',';
  50. rv += num::humanize(_minfreespace.value());
  51. }
  52. return rv;
  53. }
  54. void
  55. Branch::set_minfreespace(const uint64_t minfreespace_)
  56. {
  57. _minfreespace = minfreespace_;
  58. }
  59. uint64_t
  60. Branch::minfreespace(void) const
  61. {
  62. if(_minfreespace.has_value())
  63. return _minfreespace.value();
  64. return *_default_minfreespace;
  65. }
  66. bool
  67. Branch::ro(void) const
  68. {
  69. return (mode == Branch::Mode::RO);
  70. }
  71. bool
  72. Branch::nc(void) const
  73. {
  74. return (mode == Branch::Mode::NC);
  75. }
  76. bool
  77. Branch::ro_or_nc(void) const
  78. {
  79. return ((mode == Branch::Mode::RO) ||
  80. (mode == Branch::Mode::NC));
  81. }