]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/info/unix/macosx/macosx.factor
specialized-arrays.direct is no more; instead, every specialized-array.<foo> vocabula...
[factor.git] / basis / io / files / info / unix / macosx / macosx.factor
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
9
10 TUPLE: macosx-file-system-info < unix-file-system-info
11 io-size owner type-id filesystem-subtype ;
12
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 ;
17
18 M: macosx new-file-system-info macosx-file-system-info new ;
19
20 M: macosx file-system-statfs ( normalized-path -- statfs )
21     \ statfs64 <struct> [ statfs64 io-error ] keep ;
22
23 M: macosx file-system-statvfs ( normalized-path -- statvfs )
24     \ statvfs <struct> [ statvfs io-error ] keep ;
25
26 M: macosx statfs>file-system-info ( file-system-info byte-array -- file-system-info' )
27     {
28         [ f_bsize>> >>block-size ]
29         [ f_iosize>> >>io-size ]
30         [ f_blocks>> >>blocks ]
31         [ f_bfree>> >>blocks-free ]
32         [ f_bavail>> >>blocks-available ]
33         [ f_files>> >>files ]
34         [ f_ffree>> >>files-free ]
35         [ f_fsid>> >>id ]
36         [ f_owner>> >>owner ]
37         [ f_type>> >>type-id ]
38         [ f_flags>> >>flags ]
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 ]
43     } cleave ;
44
45 M: macosx statvfs>file-system-info ( file-system-info byte-array -- file-system-info' )
46     {
47         [ f_frsize>> >>preferred-block-size ]
48         [ f_favail>> >>files-available ]
49         [ f_namemax>> >>name-max ]
50     } cleave ;