| 208 | }; |
| 209 | |
| 210 | class MountRootResolver { |
| 211 | private: |
| 212 | std::unordered_map<dev_t, std::string> dmm; |
| 213 | |
| 214 | public: |
| 215 | explicit MountRootResolver(const std::vector<MountInfo>& mounts) { |
| 216 | for (const auto& mount : mounts) { |
| 217 | if (mount.getRoot() == "/") { |
| 218 | dmm[mount.getDev()] = mount.getMountPoint(); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | ~MountRootResolver() = default; |
| 224 | |
| 225 | std::string resolveRoot(const MountInfo& mount) { |
| 226 | auto dev = mount.getDev(); |
| 227 | auto it = dmm.find(dev); |
| 228 | if (it != dmm.end()) { |
| 229 | if (it->second != "/") |
| 230 | return it->second + mount.getRoot(); |
| 231 | } |
| 232 | return mount.getRoot(); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | std::vector<MountInfo> getMountInfo(const std::string& path = "/proc/self/mountinfo") { |
| 237 | std::ifstream mi(path); |
nothing calls this directly
no outgoing calls
no test coverage detected