diff --git a/basis/unix/bsd/bsd.factor b/basis/unix/bsd/bsd.factor index bf426ad867..bd66c5253e 100644 --- a/basis/unix/bsd/bsd.factor +++ b/basis/unix/bsd/bsd.factor @@ -83,6 +83,16 @@ C-STRUCT: passwd : SEEK_CUR 1 ; inline : SEEK_END 2 ; inline +: DT_UNKNOWN 0 ; inline +: DT_FIFO 1 ; inline +: DT_CHR 2 ; inline +: DT_DIR 4 ; inline +: DT_BLK 6 ; inline +: DT_REG 8 ; inline +: DT_LNK 10 ; inline +: DT_SOCK 12 ; inline +: DT_WHT 14 ; inline + os { { macosx [ "unix.bsd.macosx" require ] } { freebsd [ "unix.bsd.freebsd" require ] } diff --git a/basis/unix/bsd/freebsd/freebsd.factor b/basis/unix/bsd/freebsd/freebsd.factor index 3af6358e94..81885ff141 100644 --- a/basis/unix/bsd/freebsd/freebsd.factor +++ b/basis/unix/bsd/freebsd/freebsd.factor @@ -20,16 +20,6 @@ C-STRUCT: dirent { "u_int8_t" "d_namlen" } { { "char" 256 } "d_name" } ; -: DT_UNKNOWN 0 ; inline -: DT_FIFO 1 ; inline -: DT_CHR 2 ; inline -: DT_DIR 4 ; inline -: DT_BLK 6 ; inline -: DT_REG 8 ; inline -: DT_LNK 10 ; inline -: DT_SOCK 12 ; inline -: DT_WHT 14 ; inline - : EPERM 1 ; inline : ENOENT 2 ; inline : ESRCH 3 ; inline diff --git a/basis/unix/bsd/macosx/macosx.factor b/basis/unix/bsd/macosx/macosx.factor index de2fd4caf0..fb9eb9a621 100644 --- a/basis/unix/bsd/macosx/macosx.factor +++ b/basis/unix/bsd/macosx/macosx.factor @@ -39,17 +39,6 @@ C-STRUCT: dirent { "__uint8_t" "d_namlen" } { { "char" __DARWIN_MAXNAMELEN+1 } "d_name" } ; -: DT_UNKNOWN 0 ; inline -: DT_FIFO 1 ; inline -: DT_CHR 2 ; inline -: DT_DIR 4 ; inline -: DT_BLK 6 ; inline -: DT_REG 8 ; inline -: DT_LNK 10 ; inline -: DT_SOCK 12 ; inline -: DT_WHT 14 ; inline - - : EPERM 1 ; inline : ENOENT 2 ; inline : ESRCH 3 ; inline diff --git a/basis/unix/bsd/netbsd/netbsd.factor b/basis/unix/bsd/netbsd/netbsd.factor index 9f9e9e5a71..149f35afce 100644 --- a/basis/unix/bsd/netbsd/netbsd.factor +++ b/basis/unix/bsd/netbsd/netbsd.factor @@ -20,16 +20,6 @@ C-STRUCT: dirent { "__uint8_t" "d_namlen" } { { "char" 256 } "d_name" } ; -: DT_UNKNOWN 0 ; inline -: DT_FIFO 1 ; inline -: DT_CHR 2 ; inline -: DT_DIR 4 ; inline -: DT_BLK 6 ; inline -: DT_REG 8 ; inline -: DT_LNK 10 ; inline -: DT_SOCK 12 ; inline -: DT_WHT 14 ; inline - : EPERM 1 ; inline : ENOENT 2 ; inline : ESRCH 3 ; inline diff --git a/basis/unix/bsd/openbsd/openbsd.factor b/basis/unix/bsd/openbsd/openbsd.factor index f4a7863fdd..a4189775e7 100644 --- a/basis/unix/bsd/openbsd/openbsd.factor +++ b/basis/unix/bsd/openbsd/openbsd.factor @@ -20,17 +20,6 @@ C-STRUCT: dirent { "__uint8_t" "d_namlen" } { { "char" 256 } "d_name" } ; -: DT_UNKNOWN 0 ; inline -: DT_FIFO 1 ; inline -: DT_CHR 2 ; inline -: DT_DIR 4 ; inline -: DT_BLK 6 ; inline -: DT_REG 8 ; inline -: DT_LNK 10 ; inline -: DT_SOCK 12 ; inline - - - : EPERM 1 ; inline : ENOENT 2 ; inline : ESRCH 3 ; inline diff --git a/basis/unix/stat/macosx/macosx.factor b/basis/unix/stat/macosx/macosx.factor index 03301d25b9..49b6709847 100644 --- a/basis/unix/stat/macosx/macosx.factor +++ b/basis/unix/stat/macosx/macosx.factor @@ -115,12 +115,6 @@ C-STRUCT: vfsquery : NFSV2_MAX_FH_SIZE 32 ; inline : NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE ; inline -! C-STRUCT: fhandle - ! { "int" "fh_len" } - ! { { "uchar" NFS_MAX_FH_SIZE } "fh_data" } ; - -! TYPEDEF: fhandle fhandle_t - : MFSNAMELEN 15 ; inline : MNAMELEN 90 ; inline : MFSTYPENAMELEN 16 ; inline diff --git a/basis/unix/statfs/authors.txt b/basis/unix/statfs/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/unix/statfs/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/unix/statfs/linux/authors.txt b/basis/unix/statfs/linux/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/unix/statfs/linux/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/unix/statfs/linux/linux-tests.factor b/basis/unix/statfs/linux/linux-tests.factor new file mode 100644 index 0000000000..549905f081 --- /dev/null +++ b/basis/unix/statfs/linux/linux-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test unix.statfs.linux ; +IN: unix.statfs.linux.tests diff --git a/basis/unix/statfs/linux/linux.factor b/basis/unix/statfs/linux/linux.factor new file mode 100644 index 0000000000..b758503ab5 --- /dev/null +++ b/basis/unix/statfs/linux/linux.factor @@ -0,0 +1,28 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types combinators kernel ; +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 + { + [ 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 ; + +: statfs ( path -- byte-array ) + "statfs64" [ statfs64 io-error ] keep ; + diff --git a/basis/unix/statfs/linux/tags.txt b/basis/unix/statfs/linux/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/unix/statfs/linux/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/unix/statfs/macosx/authors.txt b/basis/unix/statfs/macosx/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/unix/statfs/macosx/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/unix/statfs/macosx/macosx-tests.factor b/basis/unix/statfs/macosx/macosx-tests.factor new file mode 100644 index 0000000000..35625e2198 --- /dev/null +++ b/basis/unix/statfs/macosx/macosx-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test unix.statfs.macosx ; +IN: unix.statfs.macosx.tests diff --git a/basis/unix/statfs/macosx/macosx.factor b/basis/unix/statfs/macosx/macosx.factor new file mode 100644 index 0000000000..60fb1658c5 --- /dev/null +++ b/basis/unix/statfs/macosx/macosx.factor @@ -0,0 +1,52 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types io.encodings.utf8 io.encodings.string +kernel sequences unix.stat accessors unix combinators math +grouping system unix.statfs io.files io.backend alien.strings ; +IN: unix.statfs.macosx + +TUPLE: macosx-file-system-info < file-system-info +block-size io-size blocks blocks-free blocks-available files +files-free file-system-id owner type flags filesystem-subtype +file-system-type-name mount-from ; + +M: macosx mounted* ( -- array ) + f dup 0 getmntinfo64 dup io-error + [ *void* ] dip + "statfs64" heap-size [ * memory>byte-array ] keep group ; + +: statfs64>file-system-info ( byte-array -- file-system-info ) + [ \ macosx-file-system-info new ] dip + { + [ + [ statfs64-f_bavail ] [ statfs64-f_bsize ] bi * + >>free-space + ] + [ statfs64-f_mntonname utf8 alien>string >>mount-on ] + [ statfs64-f_bsize >>block-size ] + + [ statfs64-f_iosize >>io-size ] + [ statfs64-f_blocks >>blocks ] + [ statfs64-f_bfree >>blocks-free ] + [ statfs64-f_bavail >>blocks-available ] + [ statfs64-f_files >>files ] + [ statfs64-f_ffree >>files-free ] + [ statfs64-f_fsid >>file-system-id ] + [ statfs64-f_owner >>owner ] + [ statfs64-f_type >>type ] + [ statfs64-f_flags >>flags ] + [ statfs64-f_fssubtype >>filesystem-subtype ] + [ + statfs64-f_fstypename utf8 alien>string + >>file-system-type-name + ] + [ + statfs64-f_mntfromname + utf8 alien>string >>mount-from + ] + } cleave ; + +M: macosx file-system-info ( path -- file-system-info ) + normalize-path + "statfs64" tuck statfs64 io-error + statfs64>file-system-info ; diff --git a/basis/unix/statfs/macosx/tags.txt b/basis/unix/statfs/macosx/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/unix/statfs/macosx/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/unix/statfs/statfs-tests.factor b/basis/unix/statfs/statfs-tests.factor new file mode 100644 index 0000000000..39bc77fc87 --- /dev/null +++ b/basis/unix/statfs/statfs-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test unix.statfs ; +IN: unix.statfs.tests diff --git a/basis/unix/statfs/statfs.factor b/basis/unix/statfs/statfs.factor new file mode 100644 index 0000000000..0d99b57faf --- /dev/null +++ b/basis/unix/statfs/statfs.factor @@ -0,0 +1,31 @@ +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: sequences system vocabs.loader combinators accessors +kernel math.order sorting ; +IN: unix.statfs + +TUPLE: mounted block-size io-size blocks blocks-free +blocks-available files files-free file-system-id owner type +flags filesystem-subtype file-system-type-name mount-on +mount-from ; + +HOOK: mounted* os ( -- array ) +HOOK: mounted-struct>mounted os ( byte-array -- mounted ) + +TUPLE: file-system-info root-directory total-free-size total-size ; + +: mounted ( -- array ) + mounted* [ mounted-struct>mounted ] map ; + +: mounted-drive ( path -- mounted/f ) + mounted + [ [ mount-on>> ] bi@ <=> ] sort + [ mount-on>> head? ] with find nip ; + +os { + { linux [ "unix.statfs.linux" require ] } + { macosx [ "unix.statfs.macosx" require ] } + ! { freebsd [ "unix.statfs.freebsd" require ] } + ! { netbsd [ "unix.statfs.netbsd" require ] } + ! { openbsd [ "unix.statfs.openbsd" require ] } +} case diff --git a/basis/unix/statfs/tags.txt b/basis/unix/statfs/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/unix/statfs/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/core/io/files/files.factor b/core/io/files/files.factor index 8796834bc7..1f6a48b50e 100644 --- a/core/io/files/files.factor +++ b/core/io/files/files.factor @@ -153,7 +153,8 @@ PRIVATE> "." last-split1 nip ; ! File info -TUPLE: file-info type size permissions created modified accessed ; +TUPLE: file-info type size permissions created modified +accessed ; HOOK: file-info io-backend ( path -- info ) @@ -181,6 +182,12 @@ SYMBOL: +unknown+ : directory? ( file-info -- ? ) type>> +directory+ = ; +! File-system + +TUPLE: file-system-info mount-on free-space ; + +HOOK: file-system-info os ( path -- file-system-info ) + + +:: passwd-md5 ( magic salt password -- bytes ) + [let* | final! [ password magic salt 3append + salt password tuck 3append md5 checksum-bytes + password length + [ 16 / ceiling swap concat ] keep + head-slice append + password [ length ] [ first ] bi + '[ [ CHAR: \0 _ ? , ] each-bit ] "" make append + md5 checksum-bytes ] | + 1000 [ + "" swap + { + [ 0 bit? password final ? append ] + [ 3 mod 0 > [ salt append ] when ] + [ 7 mod 0 > [ password append ] when ] + [ 0 bit? final password ? append ] + } cleave md5 checksum-bytes final! + ] each + + magic salt "$" 3append + { 12 0 6 13 1 7 14 2 8 15 3 9 5 4 10 } final nths 3 group + [ first3 [ 16 shift ] [ 8 shift ] bi* + + 4 to64 ] map concat + 11 final nth 2 to64 3append ] ; + +: parse-shadow-password ( string -- magic salt password ) + "$" split harvest first3 [ "$" tuck 3append ] 2dip ; + +: authenticate-password ( shadow password -- ? ) + '[ parse-shadow-password drop _ passwd-md5 ] keep = ;