]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/info/unix/macosx/macosx.factor
dd3e555af656580f17814b6e5789604bbabbf03a
[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.data alien.strings arrays
4 calendar.unix classes.struct combinators grouping
5 io.encodings.utf8 io.files io.files.info io.files.info.unix
6 io.files.unix libc kernel math sequences specialized-arrays
7 system unix unix.getfsstat.macosx unix.statfs.macosx
8 unix.statvfs.macosx ;
9 SPECIALIZED-ARRAY: uint
10 SPECIALIZED-ARRAY: statfs64
11 IN: io.files.info.unix.macosx
12
13 TUPLE: macosx-file-info < unix-file-info birth-time flags gen ;
14
15 M: macosx new-file-info ( -- class ) macosx-file-info new ;
16
17 M: macosx stat>file-info ( stat -- file-info )
18     [ call-next-method ] keep
19     {
20         [ st_flags>> >>flags ]
21         [ st_gen>> >>gen ]
22         [ st_birthtimespec>> timespec>unix-time >>birth-time ]
23     } cleave ;
24
25 TUPLE: macosx-file-system-info < unix-file-system-info
26 io-size owner type-id filesystem-subtype ;
27
28 M: macosx file-systems ( -- array )
29     f void* <ref> dup 0 getmntinfo64 dup io-error
30     [ void* deref ] dip \ statfs64 <c-direct-array>
31     [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ;
32
33 M: macosx new-file-system-info macosx-file-system-info new ;
34
35 M: macosx file-system-statfs ( normalized-path -- statfs )
36     \ statfs64 <struct> [ statfs64-func io-error ] keep ;
37
38 M: macosx file-system-statvfs ( normalized-path -- statvfs )
39     \ statvfs <struct> [ statvfs-func io-error ] keep ;
40
41 M: macosx statfs>file-system-info ( file-system-info byte-array -- file-system-info' )
42     {
43         [ f_bsize>> >>block-size ]
44         [ f_iosize>> >>io-size ]
45         [ f_blocks>> >>blocks ]
46         [ f_bfree>> >>blocks-free ]
47         [ f_bavail>> >>blocks-available ]
48         [ f_files>> >>files ]
49         [ f_ffree>> >>files-free ]
50         [ f_fsid>> >>id ]
51         [ f_owner>> >>owner ]
52         [ f_type>> >>type-id ]
53         [ f_flags>> >>flags ]
54         [ f_fssubtype>> >>filesystem-subtype ]
55         [ f_fstypename>> utf8 alien>string >>type ]
56         [ f_mntonname>> utf8 alien>string >>mount-point ]
57         [ f_mntfromname>> utf8 alien>string >>device-name ]
58     } cleave ;
59
60 M: macosx statvfs>file-system-info ( file-system-info byte-array -- file-system-info' )
61     {
62         [ f_frsize>> >>preferred-block-size ]
63         [ f_favail>> >>files-available ]
64         [ f_namemax>> >>name-max ]
65     } cleave ;