1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.strings combinators
4 grouping io.encodings.utf8 io.files kernel math sequences
5 system unix io.files.unix specialized-arrays.uint arrays
6 unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx
7 io.files.info.unix io.files.info classes.struct struct-arrays ;
8 IN: io.files.info.unix.macosx
10 TUPLE: macosx-file-system-info < unix-file-system-info
11 io-size owner type-id filesystem-subtype ;
13 M: macosx file-systems ( -- array )
14 f <void*> dup 0 getmntinfo64 dup io-error
15 [ *void* ] dip \ statfs64 <direct-struct-array>
16 [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ;
18 M: macosx new-file-system-info macosx-file-system-info new ;
20 M: macosx file-system-statfs ( normalized-path -- statfs )
21 \ statfs64 <struct> [ statfs64 io-error ] keep ;
23 M: macosx file-system-statvfs ( normalized-path -- statvfs )
24 \ statvfs <struct> [ statvfs io-error ] keep ;
26 M: macosx statfs>file-system-info ( file-system-info byte-array -- file-system-info' )
28 [ f_bsize>> >>block-size ]
29 [ f_iosize>> >>io-size ]
30 [ f_blocks>> >>blocks ]
31 [ f_bfree>> >>blocks-free ]
32 [ f_bavail>> >>blocks-available ]
34 [ f_ffree>> >>files-free ]
37 [ f_type>> >>type-id ]
39 [ f_fssubtype>> >>filesystem-subtype ]
40 [ f_fstypename>> utf8 alien>string >>type ]
41 [ f_mntonname>> utf8 alien>string >>mount-point ]
42 [ f_mntfromname>> utf8 alien>string >>device-name ]
45 M: macosx statvfs>file-system-info ( file-system-info byte-array -- file-system-info' )
47 [ f_frsize>> >>preferred-block-size ]
48 [ f_favail>> >>files-available ]
49 [ f_namemax>> >>name-max ]