Changeset 2645


Ignore:
Timestamp:
Oct 22, 2011, 11:36:33 PM (4 years ago)
Author:
wmb
Message:

ext2/3 file system - added ext3 journal recovery.

Location:
ofw/fs/ext2fs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ofw/fs/ext2fs/ext2fs.fth

    r1 r2645  
    1111fload ${BP}/ofw/fs/ext2fs/layout.fth
    1212fload ${BP}/ofw/fs/ext2fs/dir.fth
     13fload ${BP}/ofw/fs/ext2fs/recovery.fth
    1314fload ${BP}/ofw/fs/ext2fs/methods.fth
     15
    1416\ LICENSE_BEGIN
    1517\ Copyright (c) 2006 FirmWorks
  • ofw/fs/ext2fs/ext2test.sh

    r2625 r2645  
    6464echo REMAKING FILE
    6565rm -f "${DEVICE}"
    66 dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=8388000  2> /dev/null #8388608
     66# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=8388000  2> /dev/null #8388608
    6767# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=4194303 2> /dev/null
    68 #dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=2097151 2> /dev/null
    69 #dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=1050000 2> /dev/null
     68# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=2097151 2> /dev/null
     69# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=1050000 2> /dev/null
     70dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=10000 2> /dev/null # 5 MiB
    7071chmod 666 ${DEVICE}
    7172fi
     
    124125#/sbin/mke2fs -n -b 4096 -q ${PARTITION}
    125126# /sbin/mke2fs -n -j -O dir_index,^huge_file -E resize=8G -m 1 -b 4096 -q ${PARTITION}
    126 /sbin/mke2fs -n -j -O dir_index -m 1 -b 1024 -q ${PARTITION}
     127/sbin/mke2fs -j -O dir_index -m 1 -b 1024 -q ${PARTITION}
    127128echo "made"
    128129
     
    134135echo "mounted"
    135136
    136 echo -n "create test content and unmount ... "
     137echo "create test content"
    137138
    138139mkdir /mnt/boot
    139140cp ext2test.fth /mnt/boot/olpc.fth
    140141
    141 cd /mnt
     142pushd /mnt
    142143touch touched
    143144echo hello > hello
     
    152153mkfifo fifo
    153154mknod node b 1 1
    154 cd
     155popd
     156
     157if [ ! -b ${DEVICE} ] ; then
     158    echo -n "save dirty journal ..."
     159    sleep 10
     160    cp ${DEVICE} ${DEVICE}.dirty
     161fi
     162
     163echo -n "unmount ... "
    155164umount /mnt
     165sync
    156166
    157167if [ ! -b ${DEVICE} ] ; then
    158168   /sbin/losetup -d ${PARTITION}
     169   sync
     170   mv ${DEVICE} ${DEVICE}.clean
     171   cp ${DEVICE}.dirty ${DEVICE}.test
    159172fi
    160173
  • ofw/fs/ext2fs/layout.fth

    r1720 r2645  
    212212      get-pblk#                 ( adr pblk# )
    213213   then
    214    dup h# f8 < if  dup . ." attempt to destroy file system" cr abort  then
     214\ This interferes with journal recovery
     215\  dup h# f8 < if  dup . ." attempt to destroy file system" cr abort  then
    215216   block bsize move update
    216217;
  • ofw/fs/ext2fs/methods.fth

    r1954 r2645  
    216216
    217217   my-args " <NoFile>"  $=  if  true exit  then
     218
     219   recover?  if  process-journal  then
    218220
    219221   \ Start out in the root directory
  • ofw/fs/ext2fs/recovery.fth

    r2636 r2645  
    77constant /journal-header
    88   
    9 /journal-header
    10      /c  field >h_chksum_type
    11      /c  field >h_chksum_size
    12    2 /c*       \ Padding
    13    4 /l* field >h_chksum
    14    2 /l* field >h_commit_sec
    15      /l  field >h_commit_nsec
    16 constant /commit-header
    17 
    18 /journal-header
    19    /l field >r_count
    20 constant /revoke-header
    21 
    22 struct
    23    /l field >t_blocknr
    24    /l field >t_flags
    25 dup constant /tag32
    26    /l field >t_blocknr_high
    27 constant /tag64
    28 
     9\ Superblock - blocktype 3 (version 1) or 4 (version 2)
    2910/journal-header
    3011   /l field >s_blocksize
     
    4021drop
    4122
     23\ Commit header - blocktype 2
     24/journal-header
     25     /c  field >h_chksum_type
     26     /c  field >h_chksum_size
     27   2 /c*       \ Padding
     28   4 /l* field >h_chksum
     29   2 /l* field >h_commit_sec
     30     /l  field >h_commit_nsec
     31constant /commit-header
     32
     33\ Revoke header - blocktype 5
     34/journal-header
     35   /l field >r_count
     36constant /revoke-header
     37
     38\ Descriptor block - blocktype 1 - journal header followed by an array of tags
     39\ Tag - 32-bit and 64-bit forms
     40struct
     41   /l field >t_blocknr
     42   /l field >t_flags
     43dup constant /tag32
     44   /l field >t_blocknr_high
     45constant /tag64
     46
    42470 value j-buf
    43480 value j-compat
     
    7378
    7479   jsb >s_start be-l@  to j-start
    75    jsb 0=  if
     80   j-start 0=  if
    7681      free-journal  true exit                ( -- skip? )
    7782   then
     
    334339;
    335340: commit-journal  ( -- )
     341   jsb >s_sequence dup be-l@ 1+ swap be-l!
    336342   0 jsb >s_start be-l!
    337343   jsb 0 write-file-block
     
    341347   read-journal  if  exit  then
    342348
     349." Recovering from journal ... "
     350
    343351   0 ['] one-pass catch  if
    344352      ." Journal scan failed" cr
     
    358366   free-revoke-list
    359367
    360    \ commit-journal
     368   commit-journal
    361369   free-journal
    362 ;
     370cr
     371;
  • ofw/fs/ext2fs/sb.fth

    r1739 r2645  
    4949: #groups   ( -- n )   total-blocks bpg ceiling  ;
    5050
     51: recover?  ( -- flag )  24 +sbl 4 and 0<>  ;
     52
    5153\ Don't write to a disk that uses extensions we don't understand
    5254: unknown-extensions?   ( -- unsafe? )
    53    24 +sbl 4 and   if  ." ext3 journal needs recovery" cr  then
    54 
    5555   23 +sbl h# ffffffff invert and        \ Accept all compat extensions
    5656   24 +sbl h# 00000002 invert and  or    \ Incompatible - accept FILETYPE
Note: See TracChangeset for help on using the changeset viewer.