]> gitweb.factorcode.org Git - factor.git/blob - basis/io/unix/files/macosx/macosx.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / basis / io / unix / files / 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.unix.files specialized-arrays.direct.uint arrays
6 unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx ;
7 IN: io.unix.files.macosx
8
9 TUPLE: macosx-file-system-info < unix-file-system-info
10 io-size owner type-id filesystem-subtype ;
11
12 M: macosx file-systems ( -- array )
13     f <void*> dup 0 getmntinfo64 dup io-error
14     [ *void* ] dip
15     "statfs64" heap-size [ * memory>byte-array ] keep group
16     [ statfs64-f_mntonname utf8 alien>string file-system-info ] map ;
17     ! [ [ new-file-system-info ] dip statfs>file-system-info ] map ;
18
19 M: macosx new-file-system-info macosx-file-system-info new ;
20
21 M: macosx file-system-statfs ( normalized-path -- statfs )
22     "statfs64" <c-object> tuck statfs64 io-error ;
23
24 M: macosx file-system-statvfs ( normalized-path -- statvfs )
25     "statvfs" <c-object> tuck statvfs io-error ;
26
27 M: macosx statfs>file-system-info ( file-system-info byte-array -- file-system-info' )
28     {
29         [ statfs64-f_bsize >>block-size ]
30         [ statfs64-f_iosize >>io-size ]
31         [ statfs64-f_blocks >>blocks ]
32         [ statfs64-f_bfree >>blocks-free ]
33         [ statfs64-f_bavail >>blocks-available ]
34         [ statfs64-f_files >>files ]
35         [ statfs64-f_ffree >>files-free ]
36         [ statfs64-f_fsid 2 <direct-uint-array> >array >>id ]
37         [ statfs64-f_owner >>owner ]
38         [ statfs64-f_type >>type-id ]
39         [ statfs64-f_flags >>flags ]
40         [ statfs64-f_fssubtype >>filesystem-subtype ]
41         [ statfs64-f_fstypename utf8 alien>string >>type ]
42         [ statfs64-f_mntonname utf8 alien>string >>mount-point ]
43         [ statfs64-f_mntfromname utf8 alien>string >>device-name ]
44     } cleave ;
45
46 M: macosx statvfs>file-system-info ( file-system-info byte-array -- file-system-info' )
47     {
48         [ statvfs-f_frsize >>preferred-block-size ]
49         [ statvfs-f_favail >>files-available ]
50         [ statvfs-f_namemax >>name-max ]
51     } cleave ;