diff --git a/basis/io/unix/files/freebsd/freebsd.factor b/basis/io/unix/files/freebsd/freebsd.factor index 2c8f4bb438..3786a82b55 100644 --- a/basis/io/unix/files/freebsd/freebsd.factor +++ b/basis/io/unix/files/freebsd/freebsd.factor @@ -2,23 +2,53 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.syntax combinators io.backend io.files io.unix.files kernel math system unix -unix.statvfs.freebsd ; +unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd +sequences grouping alien.strings io.encodings.utf8 ; IN: io.unix.files.freebsd +TUPLE: freebsd-file-system-info < unix-file-system-info +version io-size owner syncreads syncwrites asyncreads asyncwrites ; + +M: freebsd new-file-system-info freebsd-file-system-info new ; + +M: freebsd file-system-statfs ( path -- byte-array ) + "statfs" tuck statfs io-error ; + +M: freebsd statfs>file-system-info ( file-system-info statvfs -- file-system-info ) + { + [ statfs-f_version >>version ] + [ statfs-f_type >>type ] + [ statfs-f_flags >>flags ] + [ statfs-f_bsize >>block-size ] + [ statfs-f_iosize >>io-size ] + [ statfs-f_blocks >>blocks ] + [ statfs-f_bfree >>blocks-free ] + [ statfs-f_bavail >>blocks-available ] + [ statfs-f_files >>files ] + [ statfs-f_ffree >>files-free ] + [ statfs-f_syncwrites >>syncwrites ] + [ statfs-f_asyncwrites >>asyncwrites ] + [ statfs-f_syncreads >>syncreads ] + [ statfs-f_asyncreads >>asyncreads ] + [ statfs-f_namemax >>name-max ] + [ statfs-f_owner >>owner ] + [ statfs-f_fsid >>id ] + [ statfs-f_fstypename utf8 alien>string >>type ] + [ statfs-f_mntfromname utf8 alien>string >>device-name ] + [ statfs-f_mntonname utf8 alien>string >>mount-point ] + } cleave ; + M: freebsd file-system-statvfs ( path -- byte-array ) "statvfs" tuck statvfs io-error ; M: freebsd statvfs>file-system-info ( file-system-info statvfs -- file-system-info ) { - [ statvfs-f_bavail >>blocks-available ] - [ statvfs-f_bfree >>blocks-free ] - [ statvfs-f_blocks >>blocks ] [ statvfs-f_favail >>files-available ] - [ statvfs-f_ffree >>files-free ] - [ statvfs-f_files >>files ] - [ statvfs-f_bsize >>block-size ] - [ statvfs-f_flag >>flags ] [ statvfs-f_frsize >>preferred-block-size ] - [ statvfs-f_fsid >>id ] - [ statvfs-f_namemax >>name-max ] } cleave ; + +M: freebsd file-systems ( -- array ) + f 0 0 getfsstat dup io-error + "statfs" dup dup length 0 getfsstat io-error + "statfs" heap-size group + [ statfs-f_mntonname alien>native-string file-system-info ] map ; diff --git a/basis/unix/getfsstat/freebsd/authors.txt b/basis/unix/getfsstat/freebsd/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/unix/getfsstat/freebsd/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/unix/getfsstat/freebsd/freebsd.factor b/basis/unix/getfsstat/freebsd/freebsd.factor new file mode 100644 index 0000000000..1d9cab577e --- /dev/null +++ b/basis/unix/getfsstat/freebsd/freebsd.factor @@ -0,0 +1,11 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.syntax ; +IN: unix.getfsstat.freebsd + +: MNT_WAIT 1 ; inline ! synchronously wait for I/O to complete +: MNT_NOWAIT 2 ; inline ! start all I/O, but do not wait for it +: MNT_LAZY 3 ; inline ! push data not written by filesystem syncer +: MNT_SUSPEND 4 ; inline ! Suspend file system after sync + +FUNCTION: int getfsstat ( statfs* buf, int bufsize, int flags ) ; diff --git a/basis/unix/getfsstat/freebsd/tags.txt b/basis/unix/getfsstat/freebsd/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/unix/getfsstat/freebsd/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/unix/statfs/freebsd/freebsd.factor b/basis/unix/statfs/freebsd/freebsd.factor index f6fcff5c7c..038178f6f8 100644 --- a/basis/unix/statfs/freebsd/freebsd.factor +++ b/basis/unix/statfs/freebsd/freebsd.factor @@ -2,3 +2,33 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien.syntax ; IN: unix.statfs.freebsd + +: MFSNAMELEN 16 ; inline ! length of type name including null */ +: MNAMELEN 88 ; inline ! size of on/from name bufs +: STATFS_VERSION HEX: 20030518 ; inline ! current version number + +C-STRUCT: statfs + { "uint32_t" "f_version" } + { "uint32_t" "f_type" } + { "uint64_t" "f_flags" } + { "uint64_t" "f_bsize" } + { "uint64_t" "f_iosize" } + { "uint64_t" "f_blocks" } + { "uint64_t" "f_bfree" } + { "int64_t" "f_bavail" } + { "uint64_t" "f_files" } + { "int64_t" "f_ffree" } + { "uint64_t" "f_syncwrites" } + { "uint64_t" "f_asyncwrites" } + { "uint64_t" "f_syncreads" } + { "uint64_t" "f_asyncreads" } + { { "uint64_t" 10 } "f_spare" } + { "uint32_t" "f_namemax" } + { "uid_t" "f_owner" } + { "fsid_t" "f_fsid" } + { { "char" 80 } "f_charspare" } + { { "char" MFSNAMELEN } "f_fstypename" } + { { "char" MNAMELEN } "f_mntfromname" } + { { "char" MNAMELEN } "f_mntonname" } ; + +FUNCTION: int statfs ( char* path, statvfs* buf ) ;