Changeset 2798
- Timestamp:
- Jan 4, 2012 9:51:42 AM (17 months ago)
- Location:
- ofw/fs/ext2fs
- Files:
-
- 1 added
- 4 edited
-
dir.fth (modified) (5 diffs)
-
ext2fs.fth (modified) (1 diff)
-
extent.fth (added)
-
layout.fth (modified) (9 diffs)
-
recovery.fth (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ofw/fs/ext2fs/dir.fth
r2796 r2798 5 5 6 6 2 constant root-dir# 7 0 instance valuedir-block#7 0. instance 2value d.dir-block# 8 8 0 instance value lblk# 9 9 … … 18 18 0 instance value wf-type \ Type - 4 for directory, d# 10 for symlink, etc 19 19 20 : find-dirblk ( -- ) 21 lblk# >d.pblk# 0= abort" EXT2 - missing directory block" to d.dir-block# 22 ; 20 23 : get-dirblk ( -- end? ) 21 24 lblk# bsize um* dfile-size d< 0= if true exit then 22 lblk# >pblk# to dir-block#25 find-dirblk 23 26 false 24 27 ; 25 28 26 29 \ **** Return the address of the current directory entry 27 : dirent ( -- adr ) d ir-block#block diroff @ + ;30 : dirent ( -- adr ) d.dir-block# d.block diroff @ + ; 28 31 \ Dirent fields: 29 32 \ 00.l inode … … 88 91 \ On entry: 89 92 \ inode# refers to the directory block's inode 90 \ d ir-block# is the physical block number of the first directory block93 \ d.dir-block# is the physical block number of the first directory block 91 94 \ diroff @ is 0 92 95 \ On successful exit: 93 \ d ir-block# is the physical block number of the current directory block96 \ d.dir-block# is the physical block number of the current directory block 94 97 \ diroff @ is the within-block offset of the new dirent 95 98 : no-dir-space? ( #needed -- true | offset-to-next false ) … … 132 135 : last-dirent ( -- free-bytes ) 133 136 dfile-size bsize um/mod nip swap 0= if 1- then to lblk# ( ) 134 lblk# >pblk# to dir-block#137 find-dirblk 135 138 (last-dirent) drop 136 139 dirent-len@ dirent-reclen - … … 294 297 \ On entry: 295 298 \ inode# is the inode of the directory file 296 \ d ir-block# is the physical block number of the first directory block299 \ d.dir-block# is the physical block number of the first directory block 297 300 \ diroff @ and totoff @ are 0 298 301 \ On successful exit: 299 \ d ir-block# is the physical block number of the current directory block302 \ d.dir-block# is the physical block number of the current directory block 300 303 \ diroff @ is the within-block offset of the directory entry that matches name$ 301 304 \ totoff @ is the overall offset of the directory entry that matches name$ -
ofw/fs/ext2fs/ext2fs.fth
r2645 r2798 9 9 fload ${BP}/ofw/fs/ext2fs/inode.fth 10 10 fload ${BP}/ofw/fs/ext2fs/bitmap.fth 11 fload ${BP}/ofw/fs/ext2fs/extent.fth 11 12 fload ${BP}/ofw/fs/ext2fs/layout.fth 12 13 fload ${BP}/ofw/fs/ext2fs/dir.fth -
ofw/fs/ext2fs/layout.fth
r2796 r2798 43 43 >ind2 ( adr ) 44 44 ; 45 : >pblk ( logical-block# -- 0 | physical-block-adr )45 : >pblk-adr ( logical-block# -- 0 | physical-block-adr ) 46 46 dup #direct-blocks < if ( lblk# ) 47 >direct exit 47 >direct exit ( -- adr ) 48 48 then ( lblk# ) 49 49 #direct-blocks - ( lblk#' ) 50 50 51 51 dup #ind-blocks1 < if ( lblk# ) 52 #direct-blocks get-direct >ind1 exit 52 #direct-blocks get-direct >ind1 exit ( -- adr ) 53 53 then 54 54 #ind-blocks1 - ( lblk#' ) 55 55 56 dup #ind-blocks2 < if 57 #direct-blocks 1+ get-direct >ind2 exit 58 then 56 dup #ind-blocks2 < if ( lblk# ) 57 #direct-blocks 1+ get-direct >ind2 exit ( -- adr ) 58 then ( lblk# ) 59 59 #ind-blocks2 - ( lblk#' ) 60 60 61 dup #ind-blocks3 < if 62 #direct-blocks 2+ get-direct >ind3 exit 63 then 64 65 drop 0 66 ; 67 : >pblk# ( logical-block# -- physical-block# ) 68 >pblk dup 0= if exit then int@ 61 dup #ind-blocks3 < if ( lblk# ) 62 #direct-blocks 2+ get-direct >ind3 exit ( -- adr ) 63 then ( lblk# ) 64 65 drop 0 ( 0 ) 66 ; 67 : >d.pblk# ( logical-block# -- false | d.physical-block# true ) 68 extent? if ( logical-block# ) 69 extent->pblk# true exit ( -- d.physical-block# true ) 70 then ( logical-block# ) 71 >pblk-adr dup 0= if ( 0 ) 72 exit ( -- false ) 73 then ( adr ) 74 int@ u>d true ( d.physical-block# true ) 69 75 ; 70 76 … … 72 78 \ writes: if any indir block is 0, allocate and return it. 73 79 74 : get-ind1 ( index block# -- adr)80 : get-ind1 ( index ind1-block# -- block# ) 75 81 >r ( index ) ( r: ind3-block# ) 76 82 r@ block over la+ int@ ( index block# ) … … 81 87 dup rot r@ block swap la+ int! update ( new-block# ) 82 88 then ( block# ) 83 r> drop 89 r> drop ( block# ) 84 90 ; 85 91 : get-ind2 ( index ind2-block# -- block# ) … … 93 99 dup rot r@ block swap la+ int! update ( index-low new-block# ) 94 100 then ( index-low block# ) 95 get-ind1 ( adr)96 r> drop 101 get-ind1 ( block# ) 102 r> drop ( block# ) 97 103 ; 98 104 : get-ind3 ( index ind3-block# -- block# ) … … 106 112 dup rot r@ block swap la+ int! update ( index-low new-block# ) 107 113 then ( index-low block# ) 108 get-ind2 ( adr)109 r> drop 114 get-ind2 ( block# ) 115 r> drop ( block# ) 110 116 ; 111 117 … … 113 119 : get-pblk# ( logical-block# -- 0 | physical-block# ) 114 120 dup #direct-blocks < if ( lblk# ) 115 dup get-direct ?dup if nip exit then ( lblk# ) 121 dup get-direct ?dup if ( lblk# pblk# ) 122 nip exit ( -- pblk# ) 123 then ( lblk# ) 116 124 117 u.add-block dup rot >direct int! update exit 125 u.add-block ( lblk# pblk# ) 126 dup rot >direct int! update ( pblk# ) 127 exit ( -- pblk# ) 118 128 then ( lblk# ) 119 129 #direct-blocks - ( lblk#' ) … … 121 131 dup #ind-blocks1 < if ( lblk# ) 122 132 #direct-blocks get-direct ?dup 0= if ( lblk# ) 123 u.add-block dup #direct-blocks put-direct 124 then ( lblk# block ) 125 get-ind1 exit 126 then 133 u.add-block ( lblk# ind1-pblk# ) 134 dup #direct-blocks put-direct ( lblk# ind1-pblk# ) 135 then ( lblk# ind1-pblk# ) 136 get-ind1 exit ( -- pblk# ) 137 then ( lblk# ) 127 138 #ind-blocks1 - ( lblk#' ) 128 139 129 140 dup #ind-blocks2 < if 130 #direct-blocks 1+ get-direct ?dup 0= if 131 u.add-block dup #direct-blocks 1+ put-direct 132 then ( lblk# block ) 133 get-ind2 exit 134 then 135 #ind-blocks2 - ( lblk#' ) 136 137 dup #ind-blocks3 < if 138 #direct-blocks 2+ get-direct ?dup 0= if 139 u.add-block dup #direct-blocks 2+ put-direct 140 then ( lblk# block ) 141 get-ind3 exit 142 then 143 144 drop 0 141 #direct-blocks 1+ get-direct ?dup 0= if ( lblk# ) 142 u.add-block ( lblk# ind2-pblk# ) 143 dup #direct-blocks 1+ put-direct ( lblk# ind2-pblk# ) 144 then ( lblk# ind2-pblk# ) 145 get-ind2 exit ( -- pblk# ) 146 then ( lblk# ) 147 #ind-blocks2 - ( lblk#' ) 148 149 dup #ind-blocks3 < if ( lblk#' ) 150 #direct-blocks 2+ get-direct ?dup 0= if ( lblk# ) 151 u.add-block ( lblk# ind3-pblk# ) 152 dup #direct-blocks 2+ put-direct ( lblk# ind3-pblk# ) 153 then ( lblk# ind3-pblk# ) 154 get-ind3 exit ( -- pblk# ) 155 then ( lblk# ) 156 157 drop 0 ( 0 ) 145 158 ; 146 159 … … 190 203 191 204 : append-block ( -- ) 192 u.add-block ( block)193 dfile-size bsize um/mod nip dup bsize um* dfile-size! ( block#blocks )194 1+ >pblk int! update205 u.add-block ( pblk# ) 206 dfile-size bsize um/mod nip dup bsize um* dfile-size! ( pblk# #blocks ) 207 1+ >pblk-adr int! update 195 208 ; 196 209 197 210 : read-file-block ( adr lblk# -- ) 198 > pblk# ?dup if ( adrpblk# )199 block swap bsize move211 >d.pblk# if ( adr d.pblk# ) 212 d.block swap bsize move 200 213 else ( adr ) 201 214 bsize erase ( ) … … 207 220 ; 208 221 : write-file-block ( adr lblk# -- ) 209 over zeroed? if \ see if it is already allocated (XXX later: deallocate it) 210 >pblk# dup 0= if 2drop exit then 211 else \ find or allocate physical block 212 get-pblk# ( adr pblk# ) 222 \ see if it is already allocated (XXX later: deallocate it) 223 over zeroed? if ( adr lblk# ) 224 >d.pblk# 0= if ( adr ) 225 drop exit ( -- ) 226 then ( d.pblk# ) 227 else ( adr lblk# ) \ find or allocate physical block 228 get-pblk# u>d ( adr d.pblk# ) 213 229 then 214 230 \ This interferes with journal recovery -
ofw/fs/ext2fs/recovery.fth
r2796 r2798 210 210 listnode 211 211 /n 2* field >o_block# 212 /n field >o_pblock#212 /n 2* field >o_pblock# 213 213 /n field >o_escaped? 214 214 nodetype: overlay-node … … 230 230 231 231 : j-read-file-block ( adr lblk# -- ) 232 > pblk# ?dup if ( adrpblk# )233 u>d find-overlay? if( adr d.pblk# node )232 >d.pblk# if ( adr d.pblk# ) 233 find-overlay? if ( adr d.pblk# node ) 234 234 nip nip ( adr node ) 235 tuck >o_pblock# l@ ( node adrpblk# )236 block over bsize move( node adr )235 tuck >o_pblock# 2@ ( node adr d.pblk# ) 236 d.block over bsize move ( node adr ) 237 237 swap >o_escaped? l@ if ( adr ) 238 238 jbd_magic swap be-l! ( ) … … 241 241 then ( ) 242 242 else ( adr d.pblk# node ) 243 2drop ( adrpblk# )244 block swap bsize move( )243 drop ( adr d.pblk# ) 244 d.block swap bsize move ( ) 245 245 then ( ) 246 246 else ( adr ) … … 253 253 >r ( escaped? log-blk# d.block# r: node ) 254 254 r@ >o_block# 2! ( escaped? log-blk# r: node ) 255 >pblk# r@ >o_pblock# l! ( escaped? r: node ) 255 >d.pblk# 0= abort" EXT3/4 bad block number in journal" 256 ( escaped? d.pblk# r: node ) 257 r@ >o_pblock# 2! ( escaped? r: node ) 256 258 r> >o_escaped? l! ( ) 257 259 ;
Note: See TracChangeset
for help on using the changeset viewer.
