@@ -343,14 +343,28 @@ open class FileManager : NSObject {
343
343
This method replaces fileSystemAttributesAtPath:.
344
344
*/
345
345
open func attributesOfFileSystem( forPath path: String ) throws -> [ FileAttributeKey : Any ] {
346
- var s = statfs ( )
347
- guard statfs ( path, & s) == 0 else {
348
- throw _NSErrorWithErrno ( errno, reading: true , path: path)
349
- }
346
+ // statvfs(2) doesn't support 64bit inode on Darwin (apfs), fallback to statfs(2)
347
+ #if os(OSX) || os(iOS)
348
+ var s = statfs ( )
349
+ guard statfs ( path, & s) == 0 else {
350
+ throw _NSErrorWithErrno ( errno, reading: true , path: path)
351
+ }
352
+ #else
353
+ var s = statvfs ( )
354
+ guard statvfs ( path, & s) == 0 else {
355
+ throw _NSErrorWithErrno ( errno, reading: true , path: path)
356
+ }
357
+ #endif
358
+
350
359
351
360
var result = [ FileAttributeKey : Any] ( )
352
- let blockSize = UInt64 ( s. f_bsize)
353
- result [ . systemNumber] = NSNumber ( value: UInt64 ( s. f_fsid. val. 0 ) )
361
+ #if os(OSX) || os(iOS)
362
+ let blockSize = UInt64 ( s. f_bsize)
363
+ result [ . systemNumber] = NSNumber ( value: UInt64 ( s. f_fsid. val. 0 ) )
364
+ #else
365
+ let blockSize = UInt64 ( s. f_frsize)
366
+ result [ . systemNumber] = NSNumber ( value: UInt64 ( s. f_fsid) )
367
+ #endif
354
368
result [ . systemSize] = NSNumber ( value: blockSize * UInt64( s. f_blocks) )
355
369
result [ . systemFreeSize] = NSNumber ( value: blockSize * UInt64( s. f_bavail) )
356
370
result [ . systemNodes] = NSNumber ( value: UInt64 ( s. f_files) )
0 commit comments