Author: wmb Date: Tue Jan 3 01:54:24 2012 New Revision: 2796 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2796
Log: EXT2 file system - converted many internal routines to use 64-bit block numbers as a step toward ext4 support.
Modified: cpu/arm/kerncode.fth forth/kernel/double.fth ofw/fs/ext2fs/bitmap.fth ofw/fs/ext2fs/blocks.fth ofw/fs/ext2fs/dir.fth ofw/fs/ext2fs/inode.fth ofw/fs/ext2fs/layout.fth ofw/fs/ext2fs/methods.fth ofw/fs/ext2fs/recovery.fth ofw/fs/ext2fs/sb.fth
Modified: cpu/arm/kerncode.fth ============================================================================== --- cpu/arm/kerncode.fth Sat Dec 31 23:25:58 2011 (r2795) +++ cpu/arm/kerncode.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -813,12 +813,24 @@ sbcs tos,r1,tos mov tos,tos,asr #0 c; +code d>= ( d1 d2 -- f ) + ldmia sp!,{r0,r1,r2} \ tos r0 r1 r2 + subs r2,r2,r0 + sbcs tos,r1,tos + mvn tos,tos,asr #0 +c; code d> ( d1 d2 -- f ) ldmia sp!,{r0,r1,r2} \ tos r0 r1 r2 subs r0,r0,r2 sbcs tos,tos,r1 mov tos,tos,asr #0 c; +code d<= ( d1 d2 -- f ) + ldmia sp!,{r0,r1,r2} \ tos r0 r1 r2 + subs r0,r0,r2 + sbcs tos,tos,r1 + mvn tos,tos,asr #0 +c; code du< ( d1 d2 -- f ) ldmia sp!,{r0,r1,r2} \ tos r0 r1 r2 subs r2,r2,r0 @@ -863,6 +875,12 @@ mvneq tos,#0 movne tos,#0 c; +code d0<> ( d -- f ) + pop r0,sp + orrs r0,r0,tos + mvnne tos,#0 + moveq tos,#0 +c; code d0< ( d -- f ) inc sp,1cell mov tos,tos,asr #0
Modified: forth/kernel/double.fth ============================================================================== --- forth/kernel/double.fth Sat Dec 31 23:25:58 2011 (r2795) +++ forth/kernel/double.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -5,12 +5,15 @@ : 2literal ( d -- ) swap [compile] literal [compile] literal ; immediate
: d0= ( d -- flag ) or 0= ; +: d0<> ( d -- flag ) or 0<> ; : d0< ( d -- flag ) nip 0< ; : d= ( d1 d2 -- flag ) d- d0= ; : d<> ( d1 d2 -- flag ) d= 0= ; : du< ( ud1 ud2 -- flag ) rot swap 2dup <> if 2swap then 2drop u< ; : d< ( d1 d2 -- flag ) 2 pick over = if drop nip u< else nip < nip then ; +: d>= ( d1 d2 -- flag ) d< 0= ; : d> ( d1 d2 -- flag ) 2swap d< ; +: d<= ( d1 d2 -- flag ) 2swap d< 0= ; : dnegate ( d -- -d ) 0 0 2swap d- ; : dabs ( d -- +d ) 2dup d0< if dnegate then ;
Modified: ofw/fs/ext2fs/bitmap.fth ============================================================================== --- ofw/fs/ext2fs/bitmap.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/bitmap.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -8,18 +8,74 @@ 0 instance value gd-modified?
: gd-update ( -- ) true to gd-modified? ; -: block-bitmap ( group# -- block# ) group-desc le-l@ ; -: inode-bitmap ( group# -- block# ) group-desc 4 + le-l@ ; -: inode-table ( group# -- block# ) group-desc 8 + le-l@ ; -: free-blocks ( group# -- n ) group-desc h# 0c + le-w@ ; +: d.block-bitmap ( group# -- d.block# ) + group-desc dup le-l@ ( adr n ) + desc64? if ( adr n ) + swap h# 20 + le-l@ ( d.block# ) + else ( adr n ) + nip u>d ( d.block# ) + then ( d.block# ) +; +: d.inode-bitmap ( group# -- d.block# ) + group-desc dup 4 + le-l@ ( adr n ) + desc64? if ( adr n ) + swap h# 24 + le-l@ ( d.block# ) + else ( adr n ) + nip u>d ( d.block# ) + then ( d.block# ) +; +[ifdef] notdef +: d.inode-table ( group# -- d.block# ) + group-desc dup 8 + le-l@ ( adr n ) + desc64? if ( adr n ) + swap h# 28 + le-l@ ( d.block# ) + else ( adr n ) + nip u>d ( d.block# ) + then ( d.block# ) +; +[then] +: free-blocks@ ( group# -- n ) + group-desc dup h# 0c + le-w@ ( adr w ) + desc64? if ( adr w ) + swap h# 2c + le-w@ wljoin ( n ) + else ( adr w ) + nip ( n ) + then ( n ) +; +: free-blocks! ( n group# -- ) + group-desc >r ( n r: adr ) + desc64? if ( n r: adr ) + lwsplit ( lo hi r: adr ) + r@ h# 2c + le-w! ( lo r: adr ) + then ( n r: adr ) + r> h# 0c + le-w! ( ) +; + : free-blocks+! ( n group# -- ) - group-desc h# 0c + - tuck le-w@ + 0 max swap le-w! gd-update + tuck free-blocks@ + 0 max ( group# n' ) + swap free-blocks! ( ) + gd-update ( ) +; +: free-inodes@ ( group# -- n ) + group-desc dup h# 0e + le-w@ ( adr lo ) + desc64? if ( adr lo ) + swap h# 2e + le-w@ wljoin ( n ) + else ( adr lo ) + nip ( n ) + then ( n ) +; +: free-inodes! ( n group# -- ) + group-desc >r ( n r: adr ) + desc64? if ( n r: adr ) + lwsplit ( lo hi r: adr ) + r@ h# 2e + le-w! ( lo r: adr ) + then ( n r: adr ) + r> h# 0e + le-w! ( ) ; -: free-inodes ( group# -- n ) group-desc h# 0e + le-w@ ; : free-inodes+! ( n inode# -- ) - group-desc h# 0e + - tuck le-w@ + swap le-w! gd-update + tuck free-inodes@ + ( group# n' ) + swap free-inodes! ( ) + gd-update ( ) ;
[ifdef] 386-assembler @@ -64,8 +120,8 @@ [then]
\ Find the first clear bit in a bitmap, set it if found -: first-free ( len block# -- false | block#-in-group true ) - block swap ( map len ) +: d.first-free ( len d.block# -- false | block#-in-group true ) + d.block swap ( map len )
2dup h# ff bskip dup 0= if ( map len 0 ) 3drop false exit @@ -88,42 +144,69 @@ swap ;
-: clear-bit? ( bit# block# -- cleared? ) - block bitup ( mask adr' ) +: d.clear-bit? ( bit# d.block# -- cleared? ) + d.block bitup ( mask adr' ) tuck c@ ( adr mask byte ) 2dup and 0= if \ Already free ( adr mask byte ) - 3drop false exit + 3drop false exit ( -- false ) then ( adr mask byte ) swap invert and ( adr byte' ) swap c! ( ) update ( ) - true + true ( true ) ;
-: free-block ( block# -- ) - datablock0 - bpg /mod ( bit# group# ) - tuck block-bitmap ( group# bit# block# ) - clear-bit? if ( group# ) - 1 swap free-blocks+! +: d.free-block ( d.block# -- ) + datablock0 u>d d- bpg um/mod ( bit# group# ) + tuck d.block-bitmap ( group# bit# d.block# ) + d.clear-bit? if ( group# ) + 1 swap free-blocks+! ( ) else ( group# ) - drop - then + drop ( ) + then ( ) ; +: n.free-block ( block# -- ) u>d d.free-block ;
-: alloc-block ( -- block# ) +: d.alloc-block ( -- d.block# ) + #groups 0 ?do ( ) + i free-blocks@ if ( ) + bpg 3 rshift bsize min ( len ) \ XXX stay in this block + i d.block-bitmap ( len d.block# ) + d.first-free if ( block#-in-group ) + -1 i free-blocks+! ( block#-in-group ) + u>d ( d.block#-in-group ) + i bpg um* d+ ( d.block#-offset ) + datablock0 u>d d+ ( d.block# ) + 2dup d.buffer bsize erase update ( d.block# ) + unloop exit ( -- d.block# ) + else ( ) + \ The allocation bitmap disagrees with the free block count, + \ so fix the free block count to prevent thrashing. + i free-blocks@ negate i free-blocks+! + then + then + loop + true abort" no free blocks found" +; +: u.alloc-block ( -- n.block# ) #groups 0 ?do ( ) - i free-blocks if ( ) + i 1+ bpg um* datablock0 u>d d+ ( d.end-block# ) + h# 1.0000.0000. d> abort" No free blocks found with 32-bit block number" ( ) + + i free-blocks@ if ( ) bpg 3 rshift bsize min ( len ) \ XXX stay in this block - i block-bitmap ( len block# ) - first-free if ( block#-in-group ) + i d.block-bitmap ( len d.block# ) + d.first-free if ( block#-in-group ) -1 i free-blocks+! ( block#-in-group ) - i bpg * + datablock0 + ( block# ) - dup buffer bsize erase update ( block# ) - unloop exit - else + u>d ( d.block#-in-group ) + i bpg um* d+ ( d.block#-offset ) + datablock0 u>d d+ ( d.block# ) + 2dup d.buffer bsize erase update ( d.block# ) + drop unloop exit ( -- n.block# ) + else ( ) \ The allocation bitmap disagrees with the free block count, \ so fix the free block count to prevent thrashing. - i free-blocks negate i free-blocks+! + i free-blocks@ negate i free-blocks+! then then loop @@ -132,8 +215,8 @@
: free-inode ( inode# -- ) 1- ipg /mod ( bit# group# ) - tuck inode-bitmap ( group# bit# block# ) - clear-bit? if ( group# ) + tuck d.inode-bitmap ( group# bit# d.block# ) + d.clear-bit? if ( group# ) 1 swap free-inodes+! else ( group# ) drop @@ -143,8 +226,8 @@ : alloc-inode ( -- inode# ) #groups 0 ?do ipg 3 rshift bsize min ( len ) \ XXX stay in this block - i inode-bitmap ( len block# ) - first-free if ( inode#-in-group ) + i d.inode-bitmap ( len d.block# ) + d.first-free if ( inode#-in-group ) -1 i free-inodes+! ( inode#-in-group ) i ipg * + 1+ ( inode# ) dup inode /inode erase update ( inode# ) @@ -155,10 +238,10 @@ ;
: update-sb ( -- ) - 0 #groups 0 ?do i free-inodes + loop total-free-inodes! - 0 #groups 0 ?do i free-blocks + loop total-free-blocks! + 0 #groups 0 ?do i free-inodes@ + loop total-free-inodes! + 0. #groups 0 ?do i free-blocks@ u>d d+ loop d.total-free-blocks! put-super-block abort" failed to update superblock " - gds /gds gds-block# write-ublocks abort" failed to update group descriptors " + gds /gds d.gds-block# d.write-ublocks abort" failed to update group descriptors " ;
: update-gds ( -- ) @@ -169,23 +252,27 @@ \ the block bitmap number in the group descriptor. If it is larger than \ the calculated block number, do the backup. #groups 1 do - i bpg * gds-fs-block# + ( possible-gn ) - dup i block-bitmap < if ( possible-gn ) - block ( gdn-adr ) - 0 group-desc ( gdn-adr gd0-adr ) - swap bsize move update ( ) - else ( possible-gn ) - drop ( ) - then ( ) + i bpg * u>d d.gds-fs-block# d+ ( d.possible-gn ) + 2dup i d.block-bitmap d< if ( d.possible-gn ) + d.block ( gdn-adr ) + 0 group-desc ( gdn-adr gd0-adr ) + swap bsize move update ( ) + else ( d.possible-gn ) + 2drop ( ) + then ( ) loop false to gd-modified? update-sb then ;
-: add-block ( -- block# ) - #blks-held 2+ #blks-held! - alloc-block +: d.add-block ( -- d.block# ) + d.#blks-held 2. d+ d.#blks-held! + d.alloc-block +; +: u.add-block ( -- block# ) + d.#blks-held 2. d+ d.#blks-held! + u.alloc-block ;
\ LICENSE_BEGIN
Modified: ofw/fs/ext2fs/blocks.fth ============================================================================== --- ofw/fs/ext2fs/blocks.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/blocks.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -13,7 +13,7 @@
struct \ buffer /n field >dirty - /n field >blk# + 2 /n * field >d.blk# \ /n field >device 0 field >data constant /buf-hdr @@ -23,21 +23,21 @@ : >buffer ( n -- adr ) >bufadr >data ; : dirty? ( n -- dirty? ) >bufadr >dirty @ ; : dirty! ( dirty? n -- ) >bufadr >dirty ! ; -: blk# ( n -- blk# ) >bufadr >blk# @ ; -: blk#! ( blk# n -- ) >bufadr >blk# ! ; +: d.blk# ( n -- d.blk# ) >bufadr >d.blk# 2@ ; +: d.blk#! ( d.blk# n -- ) >bufadr >d.blk# 2! ;
create buf-table #bufs allot
-: read-fs-block ( adr fs-blk# -- error? ) - bsize swap logbsize lshift read-ublocks +: d.read-fs-block ( adr d.fs-blk# -- error? ) + bsize -rot logbsize dlshift d.read-ublocks ; -: write-fs-block ( adr fs-blk# -- error? ) - bsize swap logbsize lshift write-ublocks +: d.write-fs-block ( adr d.fs-blk# -- error? ) + bsize -rot logbsize dlshift d.write-ublocks ;
: empty-buffers ( -- ) block-bufs /buffer #bufs * erase - #bufs 0 do -1 i blk#! loop + #bufs 0 do -1. i d.blk#! loop buf-table #bufs 0 ?do i 2dup + c! loop drop ;
@@ -65,46 +65,46 @@ : flush-buffer ( buffer# -- ) dup dirty? if ( buffer# ) false over dirty! - dup >buffer swap blk# ( buffer-adr block# ) - dup gds-fs-block# <= if - dup . ." attempt to corrupt superblock or group descriptor" abort - then - bbug? if ." W " dup . cr then - write-fs-block abort" write error " + dup >buffer swap d.blk# ( buffer-adr d.block# ) + 2dup d.gds-fs-block# d<= if ( buffer-adr d.block# ) + 2dup d. ." attempt to corrupt superblock or group descriptor" abort + then ( buffer-adr d.block# ) + bbug? if ." W " 2dup d. cr then ( buffer-adr d.block# ) + d.write-fs-block abort" write error " else drop then ; : flush ( -- ) #bufs 0 ?do i flush-buffer loop ;
-: (buffer) ( block# -- buffer-adr in-buf? ) +: d.(buffer) ( d.block# -- buffer-adr in-buf? ) \ is the block already in a buffer? - 0 - begin ( block# buf# ) - 2dup blk# = if \ found it - nip dup mru! >buffer true exit - then - - 1+ dup #bufs = - until drop \ not found ( block# ) + #bufs 0 ?do ( d.block# ) + 2dup i d.blk# d= if \ found it ( d.block# ) + 2drop i mru! ( ) + i >buffer true unloop exit ( -- buffer-adr true ) + then ( d.block# ) + loop ( d.block# )
\ free up the least-recently-used buffer - lru dup flush-buffer ( block# buf# ) + lru dup flush-buffer ( d.block# buf# )
- tuck blk#! >buffer false ( buffer-adr ) + dup >r d.blk#! ( r: buf# ) + r> >buffer false ( buffer-adr false ) ;
-: buffer ( block# -- a ) \ like block, but does no reads - (buffer) drop +: d.buffer ( d.block# -- a ) \ like block, but does no reads + d.(buffer) drop ; -: block ( block# -- a ) - dup (buffer) if nip exit then ( block# buffer-adr ) - - bbug? if ." r " over . cr then - dup rot read-fs-block abort" read error " ( buffer-adr ) +: d.block ( d.block# -- a ) + 2dup d.(buffer) if nip nip exit then ( d.block# buffer-adr ) + + bbug? if ." r " 2 pick over d. cr then ( d.block# buffer-adr ) + dup 2swap d.read-fs-block abort" read error " ( buffer-adr ) ; +: block ( block# -- a ) u>d d.block ;
-: bd ( n -- ) block bsize dump ; +: d.bd ( d -- ) d.block bsize dump ;
\ LICENSE_BEGIN \ Copyright (c) 2006 FirmWorks
Modified: ofw/fs/ext2fs/dir.fth ============================================================================== --- ofw/fs/ext2fs/dir.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/dir.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -192,9 +192,9 @@ : idelete ( -- ) \ Short symlinks hold no blocks, but have a string in the direct block list, \ so we must not interpret that string as a block list. - #blks-held if delete-blocks then + d.#blks-held d0<> if delete-blocks then
- \ clear #blks-held, link-count, etc. + \ clear d.#blks-held, link-count, etc. 0 +i /inode 6 /l* /string erase
\ delete inode, and set its deletion time. @@ -257,8 +257,8 @@ ;
: linkpath ( -- a ) - file-acl if bsize 9 rshift else 0 then ( #acl-blocks ) - #blks-held <> if \ long symbolic link path + d.file-acl d0<> if bsize 9 rshift else 0 then ( #acl-blocks ) + u>d d.#blks-held d<> if \ long symbolic link path direct0 int@ block else \ short symbolic link path direct0
Modified: ofw/fs/ext2fs/inode.fth ============================================================================== --- ofw/fs/ext2fs/inode.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/inode.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -7,15 +7,14 @@ : set-inode ( inode# -- ) to inode# ;
: ipb ( -- n ) bsize /inode / ; -: itob ( i# -- offset block# ) +: d.itob ( i# -- offset d.block# ) 1- ipg /mod ( rel-i# group ) - gpimin swap ( block# rel-i# ) - ipb /mod ( gp-block# offset rel-blk# ) - blkstofrags - rot + ( offset block# ) + d.gpimin 2>r ( rel-i# r: d.iblock# ) + ipb /mod ( offset rel-blk# r: d.iblock# ) + u>d 2r> d+ ( offset d.block# ) ;
-: inode ( i# -- adr ) itob block swap /inode * + ; +: inode ( i# -- adr ) d.itob d.block swap /inode * + ; : ind ( n -- ) inode /inode dump ; : +i ( n -- ) inode# inode + ; : file-attr ( -- attributes ) 0 +i short@ ; @@ -37,10 +36,36 @@ : gid! ( gid -- ) 24 +i short! update ; : link-count ( -- n ) 26 +i short@ ; : link-count! ( n -- ) 26 +i short! update ; -: #blks-held ( -- n ) 28 +i int@ ; -: #blks-held! ( n -- ) 28 +i int! update ; -: file-acl ( -- n ) 104 +i int@ ; -: dir-acl ( -- n ) 108 +i int@ ; + +: d.#blks-held ( -- d ) + 28 +i int@ ( n ) + \ Should be contingent on sb-huge-files? as below, but the field + \ at 116 was reserved before, so it's going to be 0 without huge files + 116 +i short@ ( d ) +\ sb-huge-files? if 116 +i short@ else u>d then ( d ) +[ifdef] inode-huge? + \ I'm not supporting the representation where the inode block + \ count is in file system blocks instead of 512-byte blocks, + \ because I can't figure out how it works in the Linux kernel. + \ I can see how it works when updating an inode, but I don't + \ see how it works with an already-created file. + inode-huge? if logbsize 9 - dlshift then ( d' ) +[then] +; + +: d.#blks-held! ( d -- ) +[ifdef] inode-huge? + 2dup h# 1.0000.0000.0000. d>= if ( d ) + logbsize 9 - drshift ( d' ) + set-inode-huge ( d ) + else ( d ) + clear-inode-huge ( d ) + then ( d ) +[then] + 116 +i short! 28 +i int! update ( ) +; +: d.file-acl ( -- d ) 104 +i int@ 118 +i short@ ; +\ : dir-acl ( -- n ) 108 +i int@ ;
d# 12 constant #direct-blocks : direct0 ( -- adr ) 40 +i ;
Modified: ofw/fs/ext2fs/layout.fth ============================================================================== --- ofw/fs/ext2fs/layout.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/layout.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -77,7 +77,7 @@ dup if ( index block# ) nip else - drop add-block ( index new-block# ) + drop u.add-block ( index new-block# ) dup rot r@ block swap la+ int! update ( new-block# ) then ( block# ) r> drop @@ -89,7 +89,7 @@ dup if ( index-low index-high block# ) nip else - drop add-block ( index-low index-high new-block# ) + drop u.add-block ( index-low index-high new-block# ) dup rot r@ block swap la+ int! update ( index-low new-block# ) then ( index-low block# ) get-ind1 ( adr ) @@ -102,7 +102,7 @@ dup if ( index-low index-high block# ) nip else - drop add-block ( index-low index-high new-block# ) + drop u.add-block ( index-low index-high new-block# ) dup rot r@ block swap la+ int! update ( index-low new-block# ) then ( index-low block# ) get-ind2 ( adr ) @@ -114,13 +114,13 @@ dup #direct-blocks < if ( lblk# ) dup get-direct ?dup if nip exit then ( lblk# )
- add-block dup rot >direct int! update exit + u.add-block dup rot >direct int! update exit then ( lblk# ) #direct-blocks - ( lblk#' )
dup #ind-blocks1 < if ( lblk# ) #direct-blocks get-direct ?dup 0= if ( lblk# ) - add-block dup #direct-blocks put-direct + u.add-block dup #direct-blocks put-direct then ( lblk# block ) get-ind1 exit then @@ -128,7 +128,7 @@
dup #ind-blocks2 < if #direct-blocks 1+ get-direct ?dup 0= if - add-block dup #direct-blocks 1+ put-direct + u.add-block dup #direct-blocks 1+ put-direct then ( lblk# block ) get-ind2 exit then @@ -136,7 +136,7 @@
dup #ind-blocks3 < if #direct-blocks 2+ get-direct ?dup 0= if - add-block dup #direct-blocks 2+ put-direct + u.add-block dup #direct-blocks 2+ put-direct then ( lblk# block ) get-ind3 exit then @@ -147,10 +147,10 @@ \ deletes
\ this code is a bit tricky, in that after deleting a block, -\ you must update the block which pointed to it. +\ you must update the block that pointed to it.
: del-blk0 ( a -- deleted? ) - int@ dup 0= if exit then free-block true + int@ dup 0= if exit then n.free-block true ; : del-blk1 ( a -- deleted? ) int@ dup 0= if exit then ( blk# ) @@ -158,7 +158,7 @@ bsize 0 do ( blk# ) dup block i + del-blk0 if 0 over block i + int! update then 4 +loop ( blk# ) - free-block true + n.free-block true ; : del-blk2 ( a -- deleted? ) int@ dup 0= if exit then ( blk# ) @@ -166,7 +166,7 @@ bsize 0 do ( blk# ) dup block i + del-blk1 if 0 over block i + int! update then 4 +loop ( blk# ) - free-block true + n.free-block true ; : del-blk3 ( a -- deleted? ) int@ dup 0= if exit then ( blk# ) @@ -174,7 +174,7 @@ bsize 0 do ( blk# ) dup block i + del-blk2 if 0 over block i + int! update then 4 +loop ( blk# ) - free-block true + n.free-block true ; : delete-directs ( -- ) #direct-blocks 0 do @@ -189,7 +189,7 @@ ;
: append-block ( -- ) - add-block ( block ) + u.add-block ( block ) dfile-size bsize um/mod nip dup bsize um* dfile-size! ( block #blocks ) 1+ >pblk int! update ; @@ -228,7 +228,7 @@ then
/gds do-alloc is gds - gds /gds gds-block# read-ublocks dup if + gds /gds d.gds-block# d.read-ublocks dup if gds /gds do-free super-block /super-block do-free exit then
Modified: ofw/fs/ext2fs/methods.fth ============================================================================== --- ofw/fs/ext2fs/methods.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/methods.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -7,7 +7,7 @@
external
-: free-bytes ( -- d ) total-free-blocks bsize um* ; +: free-bytes ( -- d ) d.total-free-blocks bsize du* ;
: $create ( name$ -- error? ) o# 100666 ($create) @@ -18,10 +18,10 @@
dirent-inode@ set-inode
- add-block ( block# ) - dfile-size h# 400. d+ dfile-size! ( block# ) - dup direct0 int! update ( block# ) - block bsize erase update \ flush ( ) + u.add-block ( u.block# ) + dfile-size h# 400. d+ dfile-size! ( u.block# ) + dup direct0 int! update ( u.block# ) + u>d d.block bsize erase update \ flush ( ) inode# first-dirent if true exit then ( ) " ." bsize inode# fill-dirent ( ) " .." wd-inum new-dirent ( error? )
Modified: ofw/fs/ext2fs/recovery.fth ============================================================================== --- ofw/fs/ext2fs/recovery.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/recovery.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -132,7 +132,7 @@ ;
: write-jblock ( d.block# adr -- ) - -rot drop write-fs-block ( error? ) + -rot d.write-fs-block ( error? ) if ." Journal recovery write error" cr abort then ;
Modified: ofw/fs/ext2fs/sb.fth ============================================================================== --- ofw/fs/ext2fs/sb.fth Sat Dec 31 23:25:58 2011 (r2795) +++ ofw/fs/ext2fs/sb.fth Tue Jan 3 01:54:24 2012 (r2796) @@ -36,17 +36,17 @@ \ /block if 1024 6 +sbl lshift to /block then /block \ ;
-: ceiling ( nom div -- n ) /mod swap if 1+ then ; +: ceiling ( nom div -- n ) ;
\ : total-inodes ( -- n ) 0 +sbl ; -: total-blocks ( -- n ) 1 +sbl ; -: total-free-blocks ( -- n ) 3 +sbl ; +: d.total-blocks ( -- d ) 1 +sbl 84 +sbl ; +: d.total-free-blocks ( -- d ) 3 +sbl 86 +sbl ; \ : total-free-inodes ( -- n ) 4 +sbl ; \ : total-free-blocks+! ( -- n ) 3 +sbl + super-block 3 la+ int! ; \ : total-free-inodes+! ( -- n ) 4 +sbl + super-block 4 la+ int! ; -: total-free-blocks! ( -- n ) super-block 3 la+ int! ; +: d.total-free-blocks! ( d -- ) super-block tuck 86 la+ int! 3 la+ int! ; : total-free-inodes! ( -- n ) super-block 4 la+ int! ; -: #groups ( -- n ) total-blocks bpg ceiling ; +: #groups ( -- n ) d.total-blocks bpg um/mod swap if 1+ then ;
: recover? ( -- flag ) 24 +sbl 4 and 0<> ;
@@ -64,21 +64,21 @@ \ Used to set partition-offset but now unnecessary as parent handles it ;
-: write-ublocks ( adr len dev-block# -- error? ) - ublock um* " seek" $call-parent ?dup if exit then ( adr len ) +: d.write-ublocks ( adr len d.dev-block# -- error? ) + ublock du* " seek" $call-parent ?dup if exit then ( adr len ) tuck " write" $call-parent <> ; : put-super-block ( -- error? ) - super-block /super-block super-block# write-ublocks + super-block /super-block super-block# u>d d.write-ublocks ;
-: read-ublocks ( adr len dev-block# -- error? ) - ublock um* " seek" $call-parent ?dup if exit then ( adr len ) +: d.read-ublocks ( adr len dev-block# -- error? ) + ublock du* " seek" $call-parent ?dup if exit then ( adr len ) tuck " read" $call-parent <> ;
: get-super-block ( -- error? ) - super-block /super-block super-block# read-ublocks ?dup if exit then + super-block /super-block super-block# u>d d.read-ublocks ?dup if exit then
['] le-l@ to int@ ['] le-w@ to short@ ['] le-l! to int! ['] le-w! to short! @@ -89,16 +89,20 @@ magic fs-magic <> ;
-: gds-fs-block# ( -- fs-block# ) - datablock0 1+ ( logical-block# ) +: d.gds-fs-block# ( -- d.fs-block# ) + datablock0 1+ u>d ( d.logical-block# ) ; -: gds-block# ( -- dev-block# ) - gds-fs-block# bsize ublock / * ( dev-block# ) +: d.gds-block# ( -- d.dev-block# ) + d.gds-fs-block# bsize ublock / du* ( dev-block# ) +; +: desc64? ( -- flag ) h# 7f +sbw 0<> ; +: /gd ( -- n ) h# 7f +sbw ?dup 0= if h# 20 then ; +: /gds ( -- size ) #groups /gd * ublock round-up ; +: group-desc ( group# -- adr ) /gd * gds + ; +: d.gpimin ( group -- d.block# ) + group-desc dup 2 la+ int@ ( adr block# ) + desc64? if swap 9 la+ int@ else nip 0 then ( d.block# ) ; -: /gds ( -- size ) #groups h# 20 * ublock round-up ; -: group-desc ( group# -- adr ) h# 20 * gds + ; -: gpimin ( group -- block# ) group-desc 2 la+ int@ ; -: blkstofrags ( #blocks -- #frags ) ; \ XXX is this needed?
\ LICENSE_BEGIN
openfirmware@openfirmware.info