| 118 | }; |
| 119 | |
| 120 | class MountInfo { |
| 121 | public: |
| 122 | explicit MountInfo(const std::string& line) { |
| 123 | std::istringstream ss(line); |
| 124 | std::vector<std::string> parts; |
| 125 | std::string token; |
| 126 | while (ss >> token) |
| 127 | parts.push_back(token); |
| 128 | auto it = std::find(parts.begin(), parts.end(), std::string("-")); |
| 129 | if (it == parts.end() || std::distance(parts.begin(), it) < 6) |
| 130 | return; |
| 131 | size_t sep_idx = std::distance(parts.begin(), it); |
| 132 | mnt_id = std::stoi(parts[0]); |
| 133 | mnt_parent_id = std::stoi(parts[1]); |
| 134 | parseMajorMinor(parts[2]); |
| 135 | root = parts[3]; |
| 136 | mnt_pnt = parts[4]; |
| 137 | parseFlags(parts[5]); |
| 138 | for (size_t i = 6; i < sep_idx; ++i) |
| 139 | parsePropagation(parts[i]); |
| 140 | fs_type = parts[sep_idx + 1]; |
| 141 | mnt_src = parts[sep_idx + 2]; |
| 142 | parseOptions(parts[sep_idx + 3]); |
| 143 | } |
| 144 | |
| 145 | ~MountInfo() = default; |
| 146 | |
| 147 | [[nodiscard]] int getMountId() const { return mnt_id; } |
| 148 | [[nodiscard]] int getParentId() const { return mnt_parent_id; } |
| 149 | [[nodiscard]] dev_t getDev() const { return dev; } |
| 150 | [[nodiscard]] const std::string& getRoot() const { return root; } |
| 151 | [[nodiscard]] const std::string& getMountPoint() const { return mnt_pnt; } |
| 152 | [[nodiscard]] MountFlags getFlags() const { return mnt_flags; } |
| 153 | [[nodiscard]] const MountPropagation& getPropagation() const { return propagation; } |
| 154 | [[nodiscard]] const std::string& getFsType() const { return fs_type; } |
| 155 | [[nodiscard]] const std::string& getMountSource() const { return mnt_src; } |
| 156 | [[nodiscard]] const MountOptions& getMountOptions() const { return mnt_opts; } |
| 157 | |
| 158 | private: |
| 159 | int mnt_id; |
| 160 | int mnt_parent_id; |
| 161 | dev_t dev = 0; |
| 162 | std::string root; |
| 163 | std::string mnt_pnt; |
| 164 | MountFlags mnt_flags = MountFlags(0); |
| 165 | MountPropagation propagation; |
| 166 | std::string fs_type; |
| 167 | std::string mnt_src; |
| 168 | MountOptions mnt_opts; |
| 169 | |
| 170 | void parseFlags(const std::string& str) { |
| 171 | std::istringstream s(str); |
| 172 | std::string opt; |
| 173 | while (std::getline(s, opt, ',')) { |
| 174 | auto it = mountFlags.find(opt); |
| 175 | if (it != mountFlags.end()) |
| 176 | mnt_flags |= it->second; |
| 177 | } |