From 8c19ab04c90bafa3ab782d1a790154e962aac82a Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 7 May 2009 16:41:37 -0500 Subject: [PATCH 2/6] use open64 instead of open on linux. use stat64 instead of stat on linux. add word to report if a file is sparse --- basis/io/directories/unix/unix.factor | 15 +++++++-- basis/io/files/info/info.factor | 5 ++- basis/unix/linux/linux.factor | 15 ++++++--- basis/unix/stat/linux/32/32.factor | 47 +++++++++++++-------------- basis/unix/stat/linux/64/64.factor | 44 ++++++++++++------------- basis/unix/types/linux/linux.factor | 4 +++ basis/unix/unix.factor | 7 ++-- 7 files changed, 79 insertions(+), 58 deletions(-) diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor index 395ce73d7c..0db91f1153 100644 --- a/basis/io/directories/unix/unix.factor +++ b/basis/io/directories/unix/unix.factor @@ -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" f [ 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 ) [ diff --git a/basis/io/files/info/info.factor b/basis/io/files/info/info.factor index 5c5d2c93d2..f16db428a8 100644 --- a/basis/io/files/info/info.factor +++ b/basis/io/files/info/info.factor @@ -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 ) diff --git a/basis/unix/linux/linux.factor b/basis/unix/linux/linux.factor index 0cf33be1bf..5a05e5c207 100644 --- a/basis/unix/linux/linux.factor +++ b/basis/unix/linux/linux.factor @@ -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 diff --git a/basis/unix/stat/linux/32/32.factor b/basis/unix/stat/linux/32/32.factor index 35963cf4ed..98c4b90f32 100644 --- a/basis/unix/stat/linux/32/32.factor +++ b/basis/unix/stat/linux/32/32.factor @@ -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 ; diff --git a/basis/unix/stat/linux/64/64.factor b/basis/unix/stat/linux/64/64.factor index 81b33f3227..98c4b90f32 100644 --- a/basis/unix/stat/linux/64/64.factor +++ b/basis/unix/stat/linux/64/64.factor @@ -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 ; diff --git a/basis/unix/types/linux/linux.factor b/basis/unix/types/linux/linux.factor index bf5d4b7f1d..b0340c1778 100644 --- a/basis/unix/types/linux/linux.factor +++ b/basis/unix/types/linux/linux.factor @@ -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 diff --git a/basis/unix/unix.factor b/basis/unix/unix.factor index 10fb2ad64f..95dca2cb34 100644 --- a/basis/unix/unix.factor +++ b/basis/unix/unix.factor @@ -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 ) -: open-file ( path flags mode -- fd ) [ open ] unix-system-call ; +M: unix open-file [ 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 From 3bf8e41eefa45cec95bd69b8be71903b05bea2b3 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 7 May 2009 16:53:32 -0500 Subject: [PATCH 3/6] fix bootstrap errors, add missing files --- basis/io/directories/unix/linux/linux.factor | 10 ++++++++++ basis/io/directories/unix/linux/tags.txt | 1 + basis/io/directories/unix/unix.factor | 4 +++- basis/unix/linux/linux.factor | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 basis/io/directories/unix/linux/linux.factor create mode 100644 basis/io/directories/unix/linux/tags.txt diff --git a/basis/io/directories/unix/linux/linux.factor b/basis/io/directories/unix/linux/linux.factor new file mode 100644 index 0000000000..ba5b27dacd --- /dev/null +++ b/basis/io/directories/unix/linux/linux.factor @@ -0,0 +1,10 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types io.directories.unix kernel system unix ; +IN: io.directories.unix.linux + +M: unix find-next-file ( DIR* -- byte-array ) + "dirent" + f + [ readdir64_r 0 = [ (io-error) ] unless ] 2keep + *void* [ drop f ] unless ; diff --git a/basis/io/directories/unix/linux/tags.txt b/basis/io/directories/unix/linux/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/io/directories/unix/linux/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor index 0db91f1153..5e2fda5848 100644 --- a/basis/io/directories/unix/unix.factor +++ b/basis/io/directories/unix/unix.factor @@ -4,7 +4,7 @@ USING: accessors alien.c-types alien.strings combinators continuations destructors fry io io.backend io.backend.unix io.directories io.encodings.binary io.encodings.utf8 io.files io.pathnames io.files.types kernel math.bitwise sequences system -unix unix.stat ; +unix unix.stat vocabs.loader ; IN: io.directories.unix : touch-mode ( -- n ) @@ -72,3 +72,5 @@ M: unix (directory-entries) ( path -- seq ) [ >directory-entry ] produce nip ] with-unix-directory ; + +os linux? [ "io.directories.unix.linux" require ] when diff --git a/basis/unix/linux/linux.factor b/basis/unix/linux/linux.factor index 5a05e5c207..43a66f2dbe 100644 --- a/basis/unix/linux/linux.factor +++ b/basis/unix/linux/linux.factor @@ -94,7 +94,7 @@ C-STRUCT: passwd { "char*" "pw_shell" } ; ! dirent64 -C-STRUCT: dirent64 +C-STRUCT: dirent { "ulonglong" "d_ino" } { "longlong" "d_off" } { "ushort" "d_reclen" } @@ -103,7 +103,7 @@ C-STRUCT: dirent64 FUNCTION: int open64 ( char* path, int flags, int prot ) ; FUNCTION: dirent64* readdir64 ( DIR* dirp ) ; -FUNCTION: int readdir64_r ( void* dirp, dirent64* entry, dirent64** result ) ; +FUNCTION: int readdir64_r ( void* dirp, dirent* entry, dirent** result ) ; M: linux open-file [ open64 ] unix-system-call ; From e3a3aea5de3173c11ca0127403c540b998ef3a46 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 11 May 2009 21:56:09 -0500 Subject: [PATCH 4/6] d_off is missing on macosx, remove for now --- basis/io/directories/unix/unix.factor | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor index 5e2fda5848..510c1cbdfa 100644 --- a/basis/io/directories/unix/unix.factor +++ b/basis/io/directories/unix/unix.factor @@ -55,14 +55,13 @@ M: unix find-next-file ( DIR* -- byte-array ) [ drop +unknown+ ] } case ; -TUPLE: unix-directory-entry < directory-entry ino off reclen ; +TUPLE: unix-directory-entry < directory-entry ino reclen ; M: unix >directory-entry ( byte-array -- directory-entry ) { [ 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 ; From 0ef5826b860eefb1608b34c472153259a1d7341c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 11 May 2009 22:03:07 -0500 Subject: [PATCH 5/6] remove the rest of the unportable fields from dirent for now --- basis/io/directories/unix/unix.factor | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/basis/io/directories/unix/unix.factor b/basis/io/directories/unix/unix.factor index 510c1cbdfa..b8b781ec12 100644 --- a/basis/io/directories/unix/unix.factor +++ b/basis/io/directories/unix/unix.factor @@ -55,15 +55,11 @@ M: unix find-next-file ( DIR* -- byte-array ) [ drop +unknown+ ] } case ; -TUPLE: unix-directory-entry < directory-entry ino reclen ; - M: unix >directory-entry ( byte-array -- directory-entry ) { [ dirent-d_name utf8 alien>string ] [ dirent-d_type dirent-type>file-type ] - [ dirent-d_ino ] - [ dirent-d_reclen ] - } cleave unix-directory-entry boa ; + } cleave directory-entry boa ; M: unix (directory-entries) ( path -- seq ) [ From d8a04418371f8fd9c8d2e95c9a284f3a85efa48a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 11 May 2009 22:04:54 -0500 Subject: [PATCH 6/6] mason.notify: fix munged refactoring --- extra/mason/notify/notify.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/mason/notify/notify.factor b/extra/mason/notify/notify.factor index c75014e1b0..6c643d64d5 100644 --- a/extra/mason/notify/notify.factor +++ b/extra/mason/notify/notify.factor @@ -16,8 +16,8 @@ IN: mason.notify ] { } make prepend [ 5 ] 2dip '[ - _ >>command _ [ +closed+ ] unless* >>stdin + _ >>command try-output-process ] retry ] [ 2drop ] if ; @@ -47,4 +47,4 @@ IN: mason.notify ] bi ; : notify-release ( archive-name -- ) - "Uploaded " prepend [ print flush ] [ mason-tweet ] bi ; \ No newline at end of file + "Uploaded " prepend [ print flush ] [ mason-tweet ] bi ;