diff --git a/CMakeLists.txt b/CMakeLists.txt index a799086ba..fc0562fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -515,7 +515,6 @@ elseif(APPLE) src/detection/cpu/cpu_apple.c src/detection/cpuusage/cpuusage_apple.c src/detection/cursor/cursor_apple.m - src/detection/disk/disk_apple.m src/detection/disk/disk_bsd.c src/detection/displayserver/displayserver_apple.c src/detection/font/font_apple.m diff --git a/src/detection/disk/disk_apple.m b/src/detection/disk/disk_apple.m deleted file mode 100644 index 81bcdeb48..000000000 --- a/src/detection/disk/disk_apple.m +++ /dev/null @@ -1,17 +0,0 @@ -#include "disk.h" - -#include -#import - -void detectFsInfo(struct statfs* fs, FFDisk* disk) -{ - // FreeBSD doesn't support these flags - if(fs->f_flags & MNT_DONTBROWSE) - disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; - else if(fs->f_flags & MNT_REMOVABLE) - disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; - else - disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; - - ffStrbufInitS(&disk->name, [NSFileManager.defaultManager displayNameAtPath:@(fs->f_mntonname)].UTF8String); -} diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 69431950f..efe98db9b 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -20,11 +20,33 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk) disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; else disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; - - ffStrbufInit(&disk->name); } -#else -void detectFsInfo(struct statfs* fs, FFDisk* disk); +#elif __APPLE__ +#include +#include + +struct VolAttrBuf { + uint32_t length; + attrreference_t volNameRef; + char volNameSpace[MAXPATHLEN]; +} __attribute__((aligned(4), packed)); + +void detectFsInfo(struct statfs* fs, FFDisk* disk) +{ + if(fs->f_flags & MNT_DONTBROWSE) + disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; + else if(fs->f_flags & MNT_REMOVABLE) + disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; + else + disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; + + struct VolAttrBuf attrBuf; + if (getattrlist(fs->f_mntonname, &(struct attrlist) { + .bitmapcount = ATTR_BIT_MAP_COUNT, + .volattr = ATTR_VOL_INFO | ATTR_VOL_NAME, + }, &attrBuf, sizeof(attrBuf), 0) == 0) + ffStrbufInitNS(&disk->name, attrBuf.volNameRef.attr_length - 1 /* excluding '\0' */, attrBuf.volNameSpace); +} #endif const char* ffDetectDisksImpl(FFlist* disks) @@ -58,6 +80,8 @@ const char* ffDetectDisksImpl(FFlist* disks) ffStrbufInitS(&disk->mountpoint, fs->f_mntonname); ffStrbufInitS(&disk->filesystem, fs->f_fstypename); + ffStrbufInit(&disk->name); + disk->type = 0; detectFsInfo(fs, disk); if(fs->f_flags & MNT_RDONLY)