Skip to content

Commit

Permalink
Disk: check for mntopt instead of statvfs when detecting read only flags
Browse files Browse the repository at this point in the history
Ref: #1343
  • Loading branch information
CarterLi committed Oct 15, 2024
1 parent cc86c2c commit a0ad38d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/detection/disk/disk_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&currentDisk->mountpoint, "/boot") || ffStrbufStartsWithS(&currentDisk->mountpoint, "/efi"))
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/detection/disk/disk_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit a0ad38d

Please sign in to comment.