2008-12-01 15:04:55 -05:00
|
|
|
! Copyright (C) 2008 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-01 17:28:22 -05:00
|
|
|
USING: accessors alien.c-types alien.syntax combinators csv
|
2013-03-15 09:40:24 -04:00
|
|
|
io.backend io.encodings.utf8 io.files io.files.info
|
2013-10-21 16:58:33 -04:00
|
|
|
io.files.unix libc libc.linux kernel math.order namespaces sequences
|
|
|
|
sorting system unix unix.statfs.linux unix.statvfs.linux io.files.links
|
2009-08-30 12:58:30 -04:00
|
|
|
arrays io.files.info.unix assocs io.pathnames unix.types
|
|
|
|
classes.struct ;
|
2009-05-16 11:50:16 -04:00
|
|
|
FROM: csv => delimiter ;
|
2008-12-14 21:03:00 -05:00
|
|
|
IN: io.files.info.unix.linux
|
2008-12-01 15:04:55 -05:00
|
|
|
|
|
|
|
TUPLE: linux-file-system-info < unix-file-system-info
|
2008-12-02 21:41:57 -05:00
|
|
|
namelen ;
|
2008-12-01 15:04:55 -05:00
|
|
|
|
2008-12-01 17:28:22 -05:00
|
|
|
M: linux new-file-system-info linux-file-system-info new ;
|
2008-12-01 15:04:55 -05:00
|
|
|
|
2014-02-27 18:26:38 -05:00
|
|
|
M: linux file-system-statfs ( path -- statfs )
|
2009-08-30 05:06:41 -04:00
|
|
|
\ statfs64 <struct> [ statfs64 io-error ] keep ;
|
2008-12-01 15:04:55 -05:00
|
|
|
|
2011-10-13 20:55:30 -04:00
|
|
|
M: linux statfs>file-system-info ( file-system-info statfs -- file-system-info' )
|
2008-12-01 15:04:55 -05:00
|
|
|
{
|
2009-08-30 05:06:41 -04:00
|
|
|
[ f_type>> >>type ]
|
|
|
|
[ f_bsize>> >>block-size ]
|
|
|
|
[ f_blocks>> >>blocks ]
|
|
|
|
[ f_bfree>> >>blocks-free ]
|
|
|
|
[ f_bavail>> >>blocks-available ]
|
|
|
|
[ f_files>> >>files ]
|
|
|
|
[ f_ffree>> >>files-free ]
|
2009-08-30 12:58:30 -04:00
|
|
|
[ f_fsid>> >>id ]
|
2009-08-30 05:06:41 -04:00
|
|
|
[ f_namelen>> >>namelen ]
|
|
|
|
[ f_frsize>> >>preferred-block-size ]
|
2008-12-02 21:41:57 -05:00
|
|
|
! [ statfs64-f_spare >>spare ]
|
2008-12-01 15:04:55 -05:00
|
|
|
} cleave ;
|
|
|
|
|
2014-02-27 18:26:38 -05:00
|
|
|
M: linux file-system-statvfs ( path -- statvfs )
|
2009-08-30 05:06:41 -04:00
|
|
|
\ statvfs64 <struct> [ statvfs64 io-error ] keep ;
|
2008-12-01 15:04:55 -05:00
|
|
|
|
2011-10-13 20:55:30 -04:00
|
|
|
M: linux statvfs>file-system-info ( file-system-info statfs -- file-system-info' )
|
2008-12-01 15:04:55 -05:00
|
|
|
{
|
2009-08-30 05:06:41 -04:00
|
|
|
[ f_flag>> >>flags ]
|
|
|
|
[ f_namemax>> >>name-max ]
|
2008-12-01 15:04:55 -05:00
|
|
|
} cleave ;
|
|
|
|
|
|
|
|
TUPLE: mtab-entry file-system-name mount-point type options
|
|
|
|
frequency pass-number ;
|
|
|
|
|
|
|
|
: mtab-csv>mtab-entry ( csv -- mtab-entry )
|
|
|
|
[ mtab-entry new ] dip
|
|
|
|
{
|
|
|
|
[ first >>file-system-name ]
|
|
|
|
[ second >>mount-point ]
|
|
|
|
[ third >>type ]
|
2013-03-15 09:40:24 -04:00
|
|
|
[ fourth string>csv first >>options ]
|
2010-08-01 08:00:03 -04:00
|
|
|
[ 4 swap ?nth [ 0 ] unless* >>frequency ]
|
|
|
|
[ 5 swap ?nth [ 0 ] unless* >>pass-number ]
|
2008-12-01 15:04:55 -05:00
|
|
|
} cleave ;
|
|
|
|
|
|
|
|
: parse-mtab ( -- array )
|
2012-07-19 16:55:34 -04:00
|
|
|
CHAR: \s [ "/etc/mtab" utf8 file>csv ] with-delimiter
|
2008-12-01 15:04:55 -05:00
|
|
|
[ mtab-csv>mtab-entry ] map ;
|
2008-12-01 17:28:22 -05:00
|
|
|
|
|
|
|
M: linux file-systems
|
|
|
|
parse-mtab [
|
|
|
|
[ mount-point>> file-system-info ] keep
|
|
|
|
{
|
|
|
|
[ file-system-name>> >>device-name ]
|
|
|
|
[ mount-point>> >>mount-point ]
|
|
|
|
[ type>> >>type ]
|
|
|
|
} cleave
|
|
|
|
] map ;
|
2008-12-02 21:41:57 -05:00
|
|
|
|
2008-12-18 19:32:00 -05:00
|
|
|
: (find-mount-point) ( path mtab-paths -- mtab-entry )
|
2009-02-18 14:34:45 -05:00
|
|
|
2dup at* [
|
2008-12-18 19:32:00 -05:00
|
|
|
2nip
|
|
|
|
] [
|
|
|
|
drop [ parent-directory ] dip (find-mount-point)
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: find-mount-point ( path -- mtab-entry )
|
2009-10-28 18:25:50 -04:00
|
|
|
resolve-symlinks
|
2008-12-18 19:32:00 -05:00
|
|
|
parse-mtab [ [ mount-point>> ] keep ] H{ } map>assoc (find-mount-point) ;
|
|
|
|
|
2011-10-13 20:38:30 -04:00
|
|
|
M: linux file-system-info ( path -- file-system-info )
|
2008-12-02 21:41:57 -05:00
|
|
|
normalize-path
|
|
|
|
[
|
|
|
|
[ new-file-system-info ] dip
|
|
|
|
[ file-system-statfs statfs>file-system-info ]
|
|
|
|
[ file-system-statvfs statvfs>file-system-info ] bi
|
|
|
|
file-system-calculations
|
|
|
|
] keep
|
2008-12-18 19:32:00 -05:00
|
|
|
find-mount-point
|
2008-12-02 21:41:57 -05:00
|
|
|
{
|
|
|
|
[ file-system-name>> >>device-name drop ]
|
|
|
|
[ mount-point>> >>mount-point drop ]
|
|
|
|
[ type>> >>type ]
|
|
|
|
} 2cleave ;
|