]> gitweb.factorcode.org Git - factor.git/commitdiff
use open64 instead of open on linux. use stat64 instead of stat on
authorerg <erg@ubuntubox.(none)>
Thu, 7 May 2009 21:41:37 +0000 (16:41 -0500)
committererg <erg@ubuntubox.(none)>
Thu, 7 May 2009 21:41:37 +0000 (16:41 -0500)
linux. add word to report if a file is sparse

basis/io/directories/unix/unix.factor
basis/io/files/info/info.factor
basis/unix/linux/linux.factor
basis/unix/stat/linux/32/32.factor
basis/unix/stat/linux/64/64.factor
basis/unix/types/linux/linux.factor
basis/unix/unix.factor

index 395ce73d7ca83e81bd62361efc6b7112caea2c4e..0db91f1153b13cf9b6281b840d3c5152e969f149 100644 (file)
@@ -34,7 +34,9 @@ M: unix copy-file ( from to -- )
     [ opendir dup [ (io-error) ] unless ] dip
     dupd curry swap '[ _ closedir io-error ] [ ] cleanup ; inline
 
-: find-next-file ( DIR* -- byte-array )
+HOOK: find-next-file os ( DIR* -- byte-array )
+
+M: unix find-next-file ( DIR* -- byte-array )
     "dirent" <c-object>
     f <void*>
     [ readdir_r 0 = [ (io-error) ] unless ] 2keep
@@ -53,9 +55,16 @@ M: unix copy-file ( from to -- )
         [ drop +unknown+ ]
     } case ;
 
+TUPLE: unix-directory-entry < directory-entry ino off reclen ;
+
 M: unix >directory-entry ( byte-array -- directory-entry )
-    [ dirent-d_name utf8 alien>string ]
-    [ dirent-d_type dirent-type>file-type ] bi directory-entry boa ;
+    {
+        [ dirent-d_name utf8 alien>string ]
+        [ dirent-d_type dirent-type>file-type ]
+        [ dirent-d_ino ]
+        [ dirent-d_off ]
+        [ dirent-d_reclen ]
+    } cleave unix-directory-entry boa ;
 
 M: unix (directory-entries) ( path -- seq )
     [
index 5c5d2c93d2f68bf90a858046acc5f114fb45b5da..f16db428a88bfb17bcb63a3d8e0a9845c76b95c7 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman, Eduardo Cavazos.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel system sequences combinators
-vocabs.loader io.files.types ;
+vocabs.loader io.files.types math ;
 IN: io.files.info
 
 ! File info
@@ -14,6 +14,9 @@ HOOK: link-info os ( path -- info )
 
 : directory? ( file-info -- ? ) type>> +directory+ = ;
 
+: sparse-file? ( file-info -- ? )
+    [ size-on-disk>> ] [ size>> ] bi < ;
+
 ! File systems
 HOOK: file-systems os ( -- array )
 
index 0cf33be1bf3514cfa99c832c47913a65cd688d57..5a05e5c2072c2cc08422dd0f84e9666c0c1e35c0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax ;
+USING: alien.syntax alien system ;
 IN: unix
 
 ! Linux.
@@ -93,13 +93,20 @@ C-STRUCT: passwd
     { "char*"  "pw_dir" }
     { "char*"  "pw_shell" } ;
 
-C-STRUCT: dirent
-    { "__ino_t" "d_ino" }
-    { "__off_t" "d_off" }
+! dirent64
+C-STRUCT: dirent64
+    { "ulonglong" "d_ino" }
+    { "longlong" "d_off" }
     { "ushort" "d_reclen" }
     { "uchar" "d_type" }
     { { "char" 256 } "d_name" } ;
 
+FUNCTION: int open64 ( char* path, int flags, int prot ) ;
+FUNCTION: dirent64* readdir64 ( DIR* dirp ) ;
+FUNCTION: int readdir64_r ( void* dirp, dirent64* entry, dirent64** result ) ;
+
+M: linux open-file [ open64 ] unix-system-call ;
+
 CONSTANT: EPERM 1
 CONSTANT: ENOENT 2
 CONSTANT: ESRCH 3
index 35963cf4edf0d157b16cf5de948454db3d928683..98c4b90f3251a6924a027bf9e852aff31a71a567 100644 (file)
@@ -1,29 +1,28 @@
-USING: kernel alien.syntax math ;
+USING: kernel alien.syntax math sequences unix
+alien.c-types arrays accessors combinators ;
 IN: unix.stat
 
-! Ubuntu 8.04 32-bit
-
+! stat64
 C-STRUCT: stat
-    { "dev_t"     "st_dev" }
-    { "ushort"    "__pad1"  }
-    { "ino_t"     "st_ino" }
-    { "mode_t"    "st_mode" }
-    { "nlink_t"   "st_nlink" }
-    { "uid_t"     "st_uid" }
-    { "gid_t"     "st_gid" }
-    { "dev_t"     "st_rdev" }
-    { "ushort"    "__pad2" }
-    { "off_t"     "st_size" }
-    { "blksize_t" "st_blksize" }
-    { "blkcnt_t"  "st_blocks" }
-    { "timespec"  "st_atimespec" }
-    { "timespec"  "st_mtimespec" }
-    { "timespec"  "st_ctimespec" }
-    { "ulong"     "unused4" }
-    { "ulong"     "unused5" } ;
+    { "dev_t"      "st_dev" }
+    { "ushort"     "__pad1" }
+    { "__ino_t"     "__st_ino" }
+    { "mode_t"     "st_mode" }
+    { "nlink_t"    "st_nlink" }
+    { "uid_t"      "st_uid" }
+    { "gid_t"      "st_gid" }
+    { "dev_t"      "st_rdev" }
+    { { "ushort" 2 } "__pad2" }
+    { "off64_t"    "st_size" }
+    { "blksize_t"  "st_blksize" }
+    { "blkcnt64_t" "st_blocks" }
+    { "timespec"   "st_atimespec" }
+    { "timespec"   "st_mtimespec" }
+    { "timespec"   "st_ctimespec" }
+    { "ulonglong"  "st_ino" } ;
 
-FUNCTION: int __xstat  ( int ver, char* pathname, stat* buf ) ;
-FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ;
+FUNCTION: int __xstat64  ( int ver, char* pathname, stat* buf ) ;
+FUNCTION: int __lxstat64 ( int ver, char* pathname, stat* buf ) ;
 
-:  stat ( pathname buf -- int ) [ 3 ] 2dip __xstat ;
-: lstat ( pathname buf -- int ) [ 3 ] 2dip __lxstat ;
+:  stat ( pathname buf -- int ) [ 1 ] 2dip __xstat64 ;
+: lstat ( pathname buf -- int ) [ 1 ] 2dip __lxstat64 ;
index 81b33f322789ee1b0511c43c3abc12f536aa4e41..98c4b90f3251a6924a027bf9e852aff31a71a567 100644 (file)
@@ -2,29 +2,27 @@ USING: kernel alien.syntax math sequences unix
 alien.c-types arrays accessors combinators ;
 IN: unix.stat
 
-! Ubuntu 7.10 64-bit
-
+! stat64
 C-STRUCT: stat
-    { "dev_t"     "st_dev" }
-    { "ino_t"     "st_ino" }
-    { "nlink_t"   "st_nlink" }
-    { "mode_t"    "st_mode" }
-    { "uid_t"     "st_uid" }
-    { "gid_t"     "st_gid" }
-    { "int"       "pad0" }
-    { "dev_t"     "st_rdev" }
-    { "off_t"     "st_size" }
-    { "blksize_t" "st_blksize" }
-    { "blkcnt_t"  "st_blocks" }
-    { "timespec"  "st_atimespec" }
-    { "timespec"  "st_mtimespec" }
-    { "timespec"  "st_ctimespec" }
-    { "long"      "__unused0" }
-    { "long"      "__unused1" }
-    { "long"      "__unused2" } ;
+    { "dev_t"      "st_dev" }
+    { "ushort"     "__pad1" }
+    { "__ino_t"     "__st_ino" }
+    { "mode_t"     "st_mode" }
+    { "nlink_t"    "st_nlink" }
+    { "uid_t"      "st_uid" }
+    { "gid_t"      "st_gid" }
+    { "dev_t"      "st_rdev" }
+    { { "ushort" 2 } "__pad2" }
+    { "off64_t"    "st_size" }
+    { "blksize_t"  "st_blksize" }
+    { "blkcnt64_t" "st_blocks" }
+    { "timespec"   "st_atimespec" }
+    { "timespec"   "st_mtimespec" }
+    { "timespec"   "st_ctimespec" }
+    { "ulonglong"  "st_ino" } ;
 
-FUNCTION: int __xstat  ( int ver, char* pathname, stat* buf ) ;
-FUNCTION: int __lxstat ( int ver, char* pathname, stat* buf ) ;
+FUNCTION: int __xstat64  ( int ver, char* pathname, stat* buf ) ;
+FUNCTION: int __lxstat64 ( int ver, char* pathname, stat* buf ) ;
 
-:  stat ( pathname buf -- int ) [ 1 ] 2dip __xstat ;
-: lstat ( pathname buf -- int ) [ 1 ] 2dip __lxstat ;
+:  stat ( pathname buf -- int ) [ 1 ] 2dip __xstat64 ;
+: lstat ( pathname buf -- int ) [ 1 ] 2dip __lxstat64 ;
index bf5d4b7f1d9f0d817e427158334618aa8f8aa3df..b0340c177827e55c88436a19fc1102fb41812b5f 100644 (file)
@@ -23,7 +23,11 @@ TYPEDEF: __slongword_type blkcnt_t
 TYPEDEF: __sword_type     ssize_t
 TYPEDEF: __s32_type       pid_t
 TYPEDEF: __slongword_type time_t
+TYPEDEF: __slongword_type __time_t
 
 TYPEDEF: ssize_t __SWORD_TYPE
+TYPEDEF: ulonglong blkcnt64_t
 TYPEDEF: ulonglong __fsblkcnt64_t
 TYPEDEF: ulonglong __fsfilcnt64_t
+TYPEDEF: ulonglong ino64_t
+TYPEDEF: ulonglong off64_t
index 10fb2ad64fbf9fc8ca5ffc40e13ee3f85df8fc88..95dca2cb34d3541efc517b215ce322df8c48d353 100644 (file)
@@ -140,9 +140,11 @@ FUNCTION: int shutdown ( int fd, int how ) ;
 
 FUNCTION: int open ( char* path, int flags, int prot ) ;
 
-FUNCTION: DIR* opendir ( char* path ) ;
+HOOK: open-file os ( path flags mode -- fd )
+
+M: unix open-file [ open ] unix-system-call ;
 
-: open-file ( path flags mode -- fd ) [ open ] unix-system-call ;
+FUNCTION: DIR* opendir ( char* path ) ;
 
 C-STRUCT: utimbuf
     { "time_t" "actime"  }
@@ -165,7 +167,6 @@ FUNCTION: ssize_t read ( int fd, void* buf, size_t nbytes ) ;
 
 FUNCTION: dirent* readdir ( DIR* dirp ) ;
 FUNCTION: int readdir_r ( void* dirp, dirent* entry, dirent** result ) ;
-
 FUNCTION: ssize_t readlink ( char* path, char* buf, size_t bufsize ) ;
 
 CONSTANT: PATH_MAX 1024