mirror of
https://github.com/darlinghq/darling-corefoundation.git
synced 2024-11-23 03:49:40 +00:00
Implement support for getting kCFURLVolumeAvailableCapacityKey and friends
This commit is contained in:
parent
93f7c0f6c8
commit
f504dcd155
@ -52,6 +52,7 @@ const CFStringRef kCFURLIsAliasFileKey = CFSTR("NSURLIsAliasFileKey");
|
||||
const CFStringRef kCFURLVolumeLocalizedFormatDescriptionKey = CFSTR("NSURLVolumeLocalizedFormatDescriptionKey");
|
||||
const CFStringRef kCFURLVolumeTotalCapacityKey = CFSTR("NSURLVolumeTotalCapacityKey");
|
||||
const CFStringRef kCFURLVolumeAvailableCapacityKey = CFSTR("NSURLVolumeAvailableCapacityKey");
|
||||
const CFStringRef kCFURLVolumeAvailableCapacityForImportantUsageKey = CFSTR("NSURLVolumeAvailableCapacityForImportantUsageKey");
|
||||
const CFStringRef kCFURLVolumeResourceCountKey = CFSTR("NSURLVolumeResourceCountKey");
|
||||
const CFStringRef kCFURLVolumeSupportsPersistentIDsKey = CFSTR("NSURLVolumeSupportsPersistentIDsKey");
|
||||
const CFStringRef kCFURLVolumeSupportsSymbolicLinksKey = CFSTR("NSURLVolumeSupportsSymbolicLinksKey");
|
||||
|
43
NSURL.m
43
NSURL.m
@ -15,6 +15,7 @@
|
||||
#import "CFPriv.h"
|
||||
#import "NSURLInternal.h"
|
||||
#import <objc/runtime.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define STACK_BUFFER_SIZE 100 // pretty safe bet this will be quite unlikely to use more than this since there are only 94 properties
|
||||
@ -449,6 +450,48 @@ static CFTypeRef CFURLCreatePropertyForKey(CFURLRef url, CFStringRef key, CFErro
|
||||
{
|
||||
// Key for the resource’s object type, returned as a CFString object. See “File Resource Types” for possible values.
|
||||
}
|
||||
else if (CFEqual(key, kCFURLVolumeAvailableCapacityKey))
|
||||
{
|
||||
UInt8 path[PATH_MAX] = { 0 };
|
||||
|
||||
if (CFURLGetFileSystemRepresentation(url, true, path, PATH_MAX))
|
||||
{
|
||||
struct statvfs vfs;
|
||||
if (statvfs(path, &vfs) == 0)
|
||||
{
|
||||
long long b = ((UInt64)vfs.f_bavail) * vfs.f_bsize;
|
||||
value = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (CFEqual(key, kCFURLVolumeAvailableCapacityForImportantUsageKey))
|
||||
{
|
||||
UInt8 path[PATH_MAX] = { 0 };
|
||||
|
||||
if (CFURLGetFileSystemRepresentation(url, true, path, PATH_MAX))
|
||||
{
|
||||
struct statvfs vfs;
|
||||
if (statvfs(path, &vfs) == 0)
|
||||
{
|
||||
long long b = ((UInt64)vfs.f_bfree) * vfs.f_bsize;
|
||||
value = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (CFEqual(key, kCFURLVolumeTotalCapacityKey))
|
||||
{
|
||||
UInt8 path[PATH_MAX] = { 0 };
|
||||
|
||||
if (CFURLGetFileSystemRepresentation(url, true, path, PATH_MAX))
|
||||
{
|
||||
struct statvfs vfs;
|
||||
if (statvfs(path, &vfs) == 0)
|
||||
{
|
||||
long long b = ((UInt64)vfs.f_blocks) * vfs.f_bsize;
|
||||
value = CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -86,6 +86,7 @@
|
||||
#define __NSi_10_11 introduced=10.11
|
||||
#define __NSi_10_12 introduced=10.12
|
||||
#define __NSi_10_12_1 introduced=10.12.1
|
||||
#define __NSi_10_13 introduced=10.13
|
||||
|
||||
#define __NSd_2_0 ,deprecated=2.0
|
||||
#define __NSd_2_1 ,deprecated=2.1
|
||||
|
@ -908,6 +908,9 @@ CF_EXPORT
|
||||
const CFStringRef kCFURLVolumeAvailableCapacityKey CF_AVAILABLE(10_6, 4_0);
|
||||
/* Total free space in bytes (Read-only, value type CFNumber) */
|
||||
|
||||
CF_EXPORT
|
||||
const CFStringRef kCFURLVolumeAvailableCapacityForImportantUsageKey CF_AVAILABLE(10_13, 11_0);
|
||||
|
||||
CF_EXPORT
|
||||
const CFStringRef kCFURLVolumeResourceCountKey CF_AVAILABLE(10_6, 4_0);
|
||||
/* Total number of resources on the volume (Read-only, value type CFNumber) */
|
||||
|
Loading…
Reference in New Issue
Block a user