ffi work
parent
e2880e8dd7
commit
deb4526bd1
|
@ -1,6 +1,5 @@
|
|||
USING: kernel alien.syntax math sequences unix
|
||||
alien.c-types arrays accessors combinators ;
|
||||
|
||||
IN: unix.stat
|
||||
|
||||
! Ubuntu 7.10 64-bit
|
||||
|
@ -30,35 +29,6 @@ FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ;
|
|||
: stat ( pathname buf -- int ) 1 -rot __xstat ;
|
||||
: lstat ( pathname buf -- int ) 1 -rot __lxstat ;
|
||||
|
||||
C-STRUCT: fstab
|
||||
{ "char*" "fs_spec" }
|
||||
{ "char*" "fs_file" }
|
||||
{ "char*" "fs_vfstype" }
|
||||
{ "char*" "fs_mntops" }
|
||||
{ "char*" "fs_type" }
|
||||
{ "int" "fs_freq" }
|
||||
{ "int" "fs_passno" } ;
|
||||
|
||||
FUNCTION: fstab* getfsent ( ) ;
|
||||
FUNCTION: fstab* getfsspec ( char* name ) ;
|
||||
FUNCTION: fstab* getfsfile ( char* name ) ;
|
||||
FUNCTION: int setfsent ( ) ;
|
||||
FUNCTION: void endfsent ( ) ;
|
||||
|
||||
TUPLE: fstab spec file vfstype mntops type freq passno ;
|
||||
|
||||
: fstab-struct>fstab ( struct -- fstab )
|
||||
[ fstab new ] dip
|
||||
{
|
||||
[ fstab-fs_spec >>spec ]
|
||||
[ fstab-fs_file >>file ]
|
||||
[ fstab-fs_vfstype >>vfstype ]
|
||||
[ fstab-fs_mntops >>mntops ]
|
||||
[ fstab-fs_type >>type ]
|
||||
[ fstab-fs_freq >>freq ]
|
||||
[ fstab-fs_passno >>passno ]
|
||||
} cleave ;
|
||||
|
||||
TYPEDEF: ssize_t __SWORD_TYPE
|
||||
TYPEDEF: ulonglong __fsblkcnt64_t
|
||||
TYPEDEF: ulonglong __fsfilcnt64_t
|
||||
|
@ -76,38 +46,4 @@ C-STRUCT: statfs64
|
|||
{ "__SWORD_TYPE" "f_frsize" }
|
||||
{ { "__SWORD_TYPE" 5 } "f_spare" } ;
|
||||
|
||||
TUPLE: statfs type bsize blocks bfree bavail files ffree fsid
|
||||
namelen frsize spare ;
|
||||
|
||||
: statfs-struct>statfs ( struct -- statfs )
|
||||
[ \ statfs new ] dip
|
||||
{
|
||||
[ statfs64-f_type >>type ]
|
||||
[ statfs64-f_bsize >>bsize ]
|
||||
[ statfs64-f_blocks >>blocks ]
|
||||
[ statfs64-f_bfree >>bfree ]
|
||||
[ statfs64-f_bavail >>bavail ]
|
||||
[ statfs64-f_files >>files ]
|
||||
[ statfs64-f_ffree >>ffree ]
|
||||
[ statfs64-f_fsid >>fsid ]
|
||||
[ statfs64-f_namelen >>namelen ]
|
||||
[ statfs64-f_frsize >>frsize ]
|
||||
[ statfs64-f_spare >>spare ]
|
||||
} cleave ;
|
||||
|
||||
FUNCTION: int statfs64 ( char* path, statfs64* buf ) ;
|
||||
: statfs ( path -- byte-array )
|
||||
"statfs64" <c-object> [ statfs64 io-error ] keep ;
|
||||
|
||||
: all-fstabs ( -- seq )
|
||||
setfsent io-error
|
||||
[ getfsent dup ] [ fstab-struct>fstab ] [ drop ] produce endfsent ;
|
||||
|
||||
C-STRUCT: mntent
|
||||
{ "char*" "mnt_fsname" }
|
||||
{ "char*" "mnt_dir" }
|
||||
{ "char*" "mnt_type" }
|
||||
{ "char*" "mnt_opts" }
|
||||
{ "int" "mnt_freq" }
|
||||
{ "int" "mnt_passno" } ;
|
||||
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.c-types combinators kernel ;
|
||||
USING: alien.c-types combinators kernel io.files unix.stat
|
||||
math accessors system unix io.backend ;
|
||||
IN: unix.statfs.linux
|
||||
|
||||
TUPLE: linux-file-system-info < file-system-info
|
||||
type bsize blocks bfree bavail files ffree fsid
|
||||
namelen frsize spare ;
|
||||
|
||||
: statfs-struct>statfs ( struct -- statfs )
|
||||
[ \ statfs new ] dip
|
||||
: statfs>file-system-info ( struct -- statfs )
|
||||
[ \ linux-file-system-info new ] dip
|
||||
{
|
||||
[
|
||||
[ statfs64-f_bsize ]
|
||||
[ statfs64-f_bavail ] bi * >>free-space
|
||||
]
|
||||
[ statfs64-f_type >>type ]
|
||||
[ statfs64-f_bsize >>bsize ]
|
||||
[ statfs64-f_blocks >>blocks ]
|
||||
|
@ -23,6 +28,7 @@ namelen frsize spare ;
|
|||
[ statfs64-f_spare >>spare ]
|
||||
} cleave ;
|
||||
|
||||
: statfs ( path -- byte-array )
|
||||
"statfs64" <c-object> [ statfs64 io-error ] keep ;
|
||||
|
||||
M: linux file-system-info ( path -- byte-array )
|
||||
normalize-path
|
||||
"statfs64" <c-object> tuck statfs64 io-error
|
||||
statfs>file-system-info ;
|
||||
|
|
Loading…
Reference in New Issue