]> gitweb.factorcode.org Git - factor.git/commitdiff
fix file-systems on freebsd
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 3 Dec 2008 02:16:53 +0000 (20:16 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 3 Dec 2008 02:16:53 +0000 (20:16 -0600)
basis/io/unix/files/freebsd/freebsd.factor
basis/unix/getfsstat/freebsd/authors.txt [new file with mode: 0644]
basis/unix/getfsstat/freebsd/freebsd.factor [new file with mode: 0644]
basis/unix/getfsstat/freebsd/tags.txt [new file with mode: 0644]
basis/unix/statfs/freebsd/freebsd.factor

index 2c8f4bb438b30d7bd9c3fcd97cb850f4cdb9eda6..3786a82b55a248d21f3a821da938e0df0f9261b5 100644 (file)
@@ -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" <c-object> 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" <c-object> 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" <c-array> 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 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -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 (file)
index 0000000..1d9cab5
--- /dev/null
@@ -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 (file)
index 0000000..6bf6830
--- /dev/null
@@ -0,0 +1 @@
+unportable
index f6fcff5c7c262dd2bae4389c7d99c33beaeb5603..038178f6f8351f018017f4dc2db51a34874dffe1 100644 (file)
@@ -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 ) ;