Author: wmb Date: Fri Jan 6 17:31:11 2012 New Revision: 2799 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2799
Log: EXT2/3/4 file systemsystem - OLPC trac #11184 - added the ability to delete extent-mapped files from an EXT4 filesystem.
Modified: ofw/fs/ext2fs/dir.fth ofw/fs/ext2fs/extent.fth ofw/fs/ext2fs/layout.fth
Modified: ofw/fs/ext2fs/dir.fth ============================================================================== --- ofw/fs/ext2fs/dir.fth Wed Jan 4 09:51:42 2012 (r2798) +++ ofw/fs/ext2fs/dir.fth Fri Jan 6 17:31:11 2012 (r2799) @@ -195,7 +195,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. - d.#blks-held d0<> if delete-blocks then + d.#blks-held d0<> if + extent? if delete-extents else delete-blocks then + then
\ clear d.#blks-held, link-count, etc. 0 +i /inode 6 /l* /string erase
Modified: ofw/fs/ext2fs/extent.fth ============================================================================== --- ofw/fs/ext2fs/extent.fth Wed Jan 4 09:51:42 2012 (r2798) +++ ofw/fs/ext2fs/extent.fth Fri Jan 6 17:31:11 2012 (r2799) @@ -1,4 +1,6 @@ -\ EXT4 extents +\ See license at end of file +purpose: EXT4 extent handling + d# 12 constant /extent-header d# 12 constant /extent-record
@@ -59,19 +61,22 @@ r> >extent ( block# 'extent ) ;
+: get-extent-block ( 'extent-index -- 'eh ) + d.block ( 'eh ) + + \ Error check + dup ext-magic? 0= if ( 'eh ) + ." EXT4 bad index block" cr + debug-me + then ( 'eh ) +; + : extent->pblk# ( logical-block# -- d.physical-block# ) direct0 ( logical-block# 'eh ) dup >eh_depth short@ 0 ?do ( logical-block# 'eh ) ext-binsearch ( logical-block# 'extent-index ) index-block@ ( logical-block# d.block# ) - d.block ( logical-block# 'eh' ) - - \ Error check - dup ext-magic? 0= if ( logical-block# 'eh' ) - ." EXT4 bad index block" cr - debug-me - then ( logical-block# 'eh' ) - + get-extent-block ( logical-block# 'eh' ) loop ( logical-block# 'eh )
ext-binsearch >r ( logical-block# r: 'extent ) @@ -85,3 +90,67 @@ then ( block-offset r: 'extent ) u>d r> extent-block@ d+ ( d.block# ) ; + +: free-extent-blocks ( 'extent -- ) + dup extent-block@ ( 'extent d.block# ) + rot >ee_len short@ 0 ?do ( d.block# ) + 2dup d.free-block ( d.block# ) + 1. d+ ( d.block#' ) + loop ( d.block#' ) + 2drop ( ) +; + +: (delete-extents) ( 'eh level -- ) recursive + ?dup if ( 'eh level ) + \ Level nonzero means 'eh is an index, so recursively free its blocks. + 1- ( 'eh level' ) + over >eh_entries short@ ( 'eh level #entries ) + 0 ?do ( 'eh level ) + i third >extent ( 'eh level 'extent-index ) + index-block@ 2>r ( 'eh level r: d.block# ) + 2r@ get-extent-block ( 'eh level 'subordinate-eh r: d.block# ) + over (delete-extents) ( 'eh level r: d.block# ) + 2r> d.free-block ( 'eh level ) + loop ( 'eh level ) + 2drop ( ) + else ( 'eh ) + \ Level 0 means 'eh is an extent list + \ For each extent in the list ... + dup >eh_entries short@ 0 ?do ( 'eh ) + \ Free all the blocks in that extent + i over >extent free-extent-blocks ( 'eh ) + loop ( 'eh ) + drop ( ) + then ( ) +; + +\ Delete blocks listed in the current set of extents +: delete-extents ( -- ) + direct0 ( 'eh ) + dup >eh_depth short@ ( 'eh depth ) + (delete-extents) ( ) +; + +\ LICENSE_BEGIN +\ Copyright (c) 2012 FirmWorks +\ +\ Permission is hereby granted, free of charge, to any person obtaining +\ a copy of this software and associated documentation files (the +\ "Software"), to deal in the Software without restriction, including +\ without limitation the rights to use, copy, modify, merge, publish, +\ distribute, sublicense, and/or sell copies of the Software, and to +\ permit persons to whom the Software is furnished to do so, subject to +\ the following conditions: +\ +\ The above copyright notice and this permission notice shall be +\ included in all copies or substantial portions of the Software. +\ +\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +\ +\ LICENSE_END
Modified: ofw/fs/ext2fs/layout.fth ============================================================================== --- ofw/fs/ext2fs/layout.fth Wed Jan 4 09:51:42 2012 (r2798) +++ ofw/fs/ext2fs/layout.fth Fri Jan 6 17:31:11 2012 (r2799) @@ -195,6 +195,7 @@ loop ; : delete-blocks ( -- ) + extent? if delete-extents exit then delete-directs indirect1 del-blk1 if 0 indirect1 int! update then indirect2 del-blk2 if 0 indirect2 int! update then
openfirmware@openfirmware.info