Author: wmb Date: Sun Oct 23 01:36:33 2011 New Revision: 2645 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2645
Log: ext2/3 file system - added ext3 journal recovery.
Modified: ofw/fs/ext2fs/ext2fs.fth ofw/fs/ext2fs/ext2test.sh ofw/fs/ext2fs/layout.fth ofw/fs/ext2fs/methods.fth ofw/fs/ext2fs/recovery.fth ofw/fs/ext2fs/sb.fth
Modified: ofw/fs/ext2fs/ext2fs.fth ============================================================================== --- ofw/fs/ext2fs/ext2fs.fth Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/ext2fs.fth Sun Oct 23 01:36:33 2011 (r2645) @@ -10,7 +10,9 @@ fload ${BP}/ofw/fs/ext2fs/bitmap.fth fload ${BP}/ofw/fs/ext2fs/layout.fth fload ${BP}/ofw/fs/ext2fs/dir.fth +fload ${BP}/ofw/fs/ext2fs/recovery.fth fload ${BP}/ofw/fs/ext2fs/methods.fth + \ LICENSE_BEGIN \ Copyright (c) 2006 FirmWorks \
Modified: ofw/fs/ext2fs/ext2test.sh ============================================================================== --- ofw/fs/ext2fs/ext2test.sh Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/ext2test.sh Sun Oct 23 01:36:33 2011 (r2645) @@ -63,10 +63,11 @@ if [ ! -b "${DEVICE}" ]; then echo REMAKING FILE rm -f "${DEVICE}" -dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=8388000 2> /dev/null #8388608 +# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=8388000 2> /dev/null #8388608 # dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=4194303 2> /dev/null -#dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=2097151 2> /dev/null -#dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=1050000 2> /dev/null +# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=2097151 2> /dev/null +# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=1050000 2> /dev/null +dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=10000 2> /dev/null # 5 MiB chmod 666 ${DEVICE} fi # if [ ! -b "${DEVICE}" -a ! -f "${DEVICE}" ]; then @@ -123,7 +124,7 @@ echo -n "make filesystem ... " #/sbin/mke2fs -n -b 4096 -q ${PARTITION} # /sbin/mke2fs -n -j -O dir_index,^huge_file -E resize=8G -m 1 -b 4096 -q ${PARTITION} -/sbin/mke2fs -n -j -O dir_index -m 1 -b 1024 -q ${PARTITION} +/sbin/mke2fs -j -O dir_index -m 1 -b 1024 -q ${PARTITION} echo "made"
# we occasionally get @@ -133,12 +134,12 @@ until mount ${PARTITION} /mnt; do sleep 0.1; done echo "mounted"
-echo -n "create test content and unmount ... " +echo "create test content"
mkdir /mnt/boot cp ext2test.fth /mnt/boot/olpc.fth
-cd /mnt +pushd /mnt touch touched echo hello > hello echo hello world > hello-world @@ -151,11 +152,23 @@ echo hello world down here > directory/hw mkfifo fifo mknod node b 1 1 -cd +popd + +if [ ! -b ${DEVICE} ] ; then + echo -n "save dirty journal ..." + sleep 10 + cp ${DEVICE} ${DEVICE}.dirty +fi + +echo -n "unmount ... " umount /mnt +sync
if [ ! -b ${DEVICE} ] ; then /sbin/losetup -d ${PARTITION} + sync + mv ${DEVICE} ${DEVICE}.clean + cp ${DEVICE}.dirty ${DEVICE}.test fi
echo "finished"
Modified: ofw/fs/ext2fs/layout.fth ============================================================================== --- ofw/fs/ext2fs/layout.fth Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/layout.fth Sun Oct 23 01:36:33 2011 (r2645) @@ -211,7 +211,8 @@ else \ find or allocate physical block get-pblk# ( adr pblk# ) then - dup h# f8 < if dup . ." attempt to destroy file system" cr abort then +\ This interferes with journal recovery +\ dup h# f8 < if dup . ." attempt to destroy file system" cr abort then block bsize move update ;
Modified: ofw/fs/ext2fs/methods.fth ============================================================================== --- ofw/fs/ext2fs/methods.fth Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/methods.fth Sun Oct 23 01:36:33 2011 (r2645) @@ -216,6 +216,8 @@
my-args " <NoFile>" $= if true exit then
+ recover? if process-journal then + \ Start out in the root directory set-root
Modified: ofw/fs/ext2fs/recovery.fth ============================================================================== --- ofw/fs/ext2fs/recovery.fth Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/recovery.fth Sun Oct 23 01:36:33 2011 (r2645) @@ -6,6 +6,21 @@ /l field >h_sequence constant /journal-header
+\ Superblock - blocktype 3 (version 1) or 4 (version 2) +/journal-header + /l field >s_blocksize + /l field >s_maxlen + /l field >s_first + /l field >s_sequence + /l field >s_start + /l field >s_errno + /l field >s_feature_compat + /l field >s_feature_incompat + /l field >s_feature_ro_compat + \ We don't need the rest +drop + +\ Commit header - blocktype 2 /journal-header /c field >h_chksum_type /c field >h_chksum_size @@ -15,10 +30,13 @@ /l field >h_commit_nsec constant /commit-header
+\ Revoke header - blocktype 5 /journal-header /l field >r_count constant /revoke-header
+\ Descriptor block - blocktype 1 - journal header followed by an array of tags +\ Tag - 32-bit and 64-bit forms struct /l field >t_blocknr /l field >t_flags @@ -26,19 +44,6 @@ /l field >t_blocknr_high constant /tag64
-/journal-header - /l field >s_blocksize - /l field >s_maxlen - /l field >s_first - /l field >s_sequence - /l field >s_start - /l field >s_errno - /l field >s_feature_compat - /l field >s_feature_incompat - /l field >s_feature_ro_compat - \ We don't need the rest -drop - 0 value j-buf 0 value j-compat 0 value j-incompat @@ -72,7 +77,7 @@ then
jsb >s_start be-l@ to j-start - jsb 0= if + j-start 0= if free-journal true exit ( -- skip? ) then
@@ -333,6 +338,7 @@ then ; : commit-journal ( -- ) + jsb >s_sequence dup be-l@ 1+ swap be-l! 0 jsb >s_start be-l! jsb 0 write-file-block flush @@ -340,6 +346,8 @@ : process-journal ( -- ) read-journal if exit then
+." Recovering from journal ... " + 0 ['] one-pass catch if ." Journal scan failed" cr free-journal exit @@ -357,6 +365,7 @@
free-revoke-list
- \ commit-journal + commit-journal free-journal +cr ;
Modified: ofw/fs/ext2fs/sb.fth ============================================================================== --- ofw/fs/ext2fs/sb.fth Sat Oct 22 12:40:13 2011 (r2644) +++ ofw/fs/ext2fs/sb.fth Sun Oct 23 01:36:33 2011 (r2645) @@ -48,10 +48,10 @@ : total-free-inodes! ( -- n ) super-block 4 la+ int! ; : #groups ( -- n ) total-blocks bpg ceiling ;
+: recover? ( -- flag ) 24 +sbl 4 and 0<> ; + \ Don't write to a disk that uses extensions we don't understand : unknown-extensions? ( -- unsafe? ) - 24 +sbl 4 and if ." ext3 journal needs recovery" cr then - 23 +sbl h# ffffffff invert and \ Accept all compat extensions 24 +sbl h# 00000002 invert and or \ Incompatible - accept FILETYPE 25 +sbl h# 00000003 invert and or \ RO - accept SPARSE_SUPER and LARGE_FILE
openfirmware@openfirmware.info