Hotplug partition manager
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.
 
 
 
 
 

195 lines
3.3 KiB

  1. /*
  2. * blk_node.cpp
  3. * Copyright (C) 2021 Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org>
  4. *
  5. * This program is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * See the LICENSE file. *
  19. */
  20. #include "blk_node.h"
  21. #include <string.h>
  22. namespace Hopman {
  23. BlkNode::BlkNode( struct vdev_usb_device device )
  24. {
  25. pathname=string( device.sysfs_path );
  26. basename=getBaseName();
  27. devname="/dev/" + basename; // It should be annex.watch_dir + basename
  28. mtpt=string( device.mtpt_str );
  29. vendor=string( device.vendor_str );
  30. model=string( device.model_str );
  31. devtype=string( device.devtype_str );
  32. inode=string( device.inode_str );
  33. size=string( device.size_str );
  34. }
  35. BlkNode::~BlkNode()
  36. {
  37. }
  38. string BlkNode::getBaseName()
  39. {
  40. char sep = '/';
  41. size_t i = pathname.rfind(sep, pathname.length());
  42. if (i != string::npos) {
  43. return(pathname.substr(i+1, pathname.length() - i));
  44. }
  45. return("");
  46. }
  47. string BlkNode::getDirName()
  48. {
  49. size_t pos = 0;
  50. string token;
  51. string delimiter = "/";
  52. while ((pos = pathname.find(delimiter)) != string::npos) {
  53. token = pathname.substr(0, pos);
  54. pathname.erase(0, pos + delimiter.length());
  55. }
  56. return token;
  57. }
  58. bool BlkNode::get_removed()
  59. {
  60. return this->removed;
  61. }
  62. bool BlkNode::get_removable()
  63. {
  64. return this->removable;
  65. }
  66. void BlkNode::set_removed(bool value)
  67. {
  68. this->removed = value;
  69. }
  70. void BlkNode::set_removable(bool value)
  71. {
  72. this->removable = value;
  73. }
  74. string BlkNode::get_inode()
  75. {
  76. return this->inode;
  77. }
  78. string BlkNode::get_devname()
  79. {
  80. return this->devname;
  81. }
  82. string BlkNode::get_basename()
  83. {
  84. return this->basename;
  85. }
  86. string BlkNode::get_pathname()
  87. {
  88. return this->pathname;
  89. }
  90. string BlkNode::get_dirname()
  91. {
  92. return this->dirname;
  93. }
  94. string BlkNode::get_vendor()
  95. {
  96. return this->vendor;
  97. }
  98. string BlkNode::get_model()
  99. {
  100. return this->model;
  101. }
  102. string BlkNode::get_devtype()
  103. {
  104. return this->devtype;
  105. }
  106. string BlkNode::get_size()
  107. {
  108. return this->size;
  109. }
  110. void BlkNode::set_size (string str)
  111. {
  112. this->size=str;
  113. }
  114. string BlkNode::get_label()
  115. {
  116. return this->label;
  117. }
  118. void BlkNode::set_label (string str)
  119. {
  120. this->label=str;
  121. }
  122. string BlkNode::get_fstype()
  123. {
  124. return this->fstype;
  125. }
  126. void BlkNode::set_fstype (string str)
  127. {
  128. this->fstype=str;
  129. }
  130. string BlkNode::get_uuid()
  131. {
  132. return this->uuid;
  133. }
  134. void BlkNode::set_uuid (string str)
  135. {
  136. this->uuid=str;
  137. }
  138. string BlkNode::get_partuuid()
  139. {
  140. return this->partuuid;
  141. }
  142. void BlkNode::set_partuuid (string str)
  143. {
  144. this->partuuid=str;
  145. }
  146. string BlkNode::get_mtpt()
  147. {
  148. return this->mtpt;
  149. }
  150. vector<string> BlkNode::get_children_mtpt_vector()
  151. {
  152. vector<string> v;
  153. v.begin();
  154. for(auto &u : children)
  155. v.push_back(u->get_mtpt());
  156. return v;
  157. }
  158. } // namespace Hopman