From c8f8e0c1f0a3687539a92169735845814e18c187 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 31 10月 2020 10:15:16 +0800 Subject: [PATCH] read dmi information segfault on windows --- src/library/os/linux/os_linux.cpp | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp index a5088f7..c203e4e 100644 --- a/src/library/os/linux/os_linux.cpp +++ b/src/library/os/linux/os_linux.cpp @@ -254,13 +254,14 @@ static void set_preferred_disks(std::vector<DiskInfo> &diskInfos, std::unordered_map<std::string, int> &disk_by_uuid) { FILE *fstabFile = setmntent("/etc/fstab", "r"); if (fstabFile == nullptr) { - /*fstab not accessible*/ + LOG_DEBUG("/etc/fstab not accessible"); return; } struct mntent *ent; while (nullptr != (ent = getmntent(fstabFile))) { bool found = false; std::string device_name_s(ent->mnt_fsname); + LOG_DEBUG("found fstab entry %s ", ent->mnt_fsname); if (strncmp("UUID=", ent->mnt_fsname, 5) == 0) { // fstab entry is uuid device_name_s = device_name_s.substr(5); @@ -276,6 +277,16 @@ } else { LOG_DEBUG("fstab device %s found, but no corresponding diskInfo", ent->mnt_fsname); } + } else if (strncmp("LABEL=", ent->mnt_fsname, 6) == 0) { + // fstab entry is uuid + device_name_s = device_name_s.substr(6); + for (auto &disk_info : diskInfos) { + if (device_name_s == disk_info.label) { + disk_info.preferred = true; + LOG_DEBUG("Disk %d device %s set as preferred", disk_info.id, disk_info.device); + break; + } + } } else { // fstab entry is a device auto pos = device_name_s.find_last_of("/"); -- Gitblit v1.9.1