From a0ad38d1d4eff5836b4af8de8f93dc5f6927d4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 15 Oct 2024 23:08:10 +0800 Subject: [PATCH] Disk: check for mntopt instead of statvfs when detecting read only flags Ref: #1343 --- src/detection/disk/disk_linux.c | 9 ++++----- src/detection/disk/disk_sunos.c | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 3836f6eb8..ae4de417f 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -215,7 +215,7 @@ static bool isRemovable(FFDisk* currentDisk) return ffReadFileData(sysBlockVolume, 1, &removableChar) > 0 && removableChar == '1'; } -static void detectType(const FFlist* disks, FFDisk* currentDisk) +static void detectType(const FFlist* disks, FFDisk* currentDisk, struct mntent* device) { if(ffStrbufStartsWithS(¤tDisk->mountpoint, "/boot") || ffStrbufStartsWithS(¤tDisk->mountpoint, "/efi")) currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; @@ -225,6 +225,8 @@ static void detectType(const FFlist* disks, FFDisk* currentDisk) currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; else currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; + if (hasmntopt(device, MNTOPT_RO)) + currentDisk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; } #endif @@ -251,9 +253,6 @@ static void detectStats(FFDisk* disk) disk->filesTotal = disk->filesUsed = 0; } - if(fs.f_flag & ST_RDONLY) - disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; - disk->createTime = 0; #ifdef FF_HAVE_STATX struct statx stx; @@ -298,7 +297,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) detectName(disk); // Also detects external devices //detect type - detectType(disks, disk); + detectType(disks, disk, device); //Detects stats detectStats(disk); diff --git a/src/detection/disk/disk_sunos.c b/src/detection/disk/disk_sunos.c index 91cde2333..9568a814b 100644 --- a/src/detection/disk/disk_sunos.c +++ b/src/detection/disk/disk_sunos.c @@ -72,12 +72,14 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk) static void detectType(const FFlist* disks, FFDisk* currentDisk, struct mnttab* device) { - if(ffStrContains(device->mnt_mntopts, MNTOPT_NOBROWSE)) + if(hasmntopt(device, MNTOPT_NOBROWSE)) currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; else if(isSubvolume(disks, currentDisk)) currentDisk->type = FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT; else currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; + if (hasmntopt(device, MNTOPT_RO)) + currentDisk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; } static void detectStats(FFDisk* disk) @@ -94,9 +96,6 @@ static void detectStats(FFDisk* disk) disk->filesTotal = (uint32_t) fs.f_files; disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree); - if(fs.f_flag & ST_RDONLY) - disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; - ffStrbufSetS(&disk->name, fs.f_fstr); disk->createTime = 0;