Skip to content

Commit 49e0ad5

Browse files
authored
fix mountinfo parsing (#104)
Some segments like shared:nn may not present. Use makedev for combining major and minor to support system with a lot of devices.
1 parent a3f0380 commit 49e0ad5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/common/utils/SysResource.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <filesystem>
55
#include <folly/logging/xlog.h>
66
#include <fstream>
7+
#include <sys/sysmacros.h>
78
#include <unistd.h>
89

910
#include "common/serde/Serde.h"
@@ -129,7 +130,10 @@ Result<std::vector<SysResource::DiskInfo>> SysResource::scanDiskInfo() {
129130
std::string deviceIdStr;
130131
std::string mountPath;
131132
std::string devicePath;
132-
if (is >> dummy >> dummy >> deviceIdStr >> dummy >> mountPath >> dummy >> dummy >> dummy >> dummy >> devicePath) {
133+
is >> dummy >> dummy >> deviceIdStr >> dummy >> mountPath;
134+
while((is >> dummy) && dummy != "-")
135+
;
136+
if (is >> dummy >> devicePath) {
133137
unsigned long maj, min;
134138
auto parseResult = scn::scan(deviceIdStr, "{}:{}", maj, min);
135139
if (!parseResult) {
@@ -139,7 +143,7 @@ Result<std::vector<SysResource::DiskInfo>> SysResource::scanDiskInfo() {
139143

140144
if (deviceToUUID.count(devicePath)) {
141145
infos.emplace_back();
142-
infos.back().deviceId = maj * 256 + min;
146+
infos.back().deviceId = makedev(maj, min);
143147
infos.back().uuid = deviceToUUID[devicePath];
144148
infos.back().devicePath = devicePath;
145149
infos.back().mountPath = mountPath;

0 commit comments

Comments
 (0)