[openfirmware] r1657 - ofw/fs/ext2fs

svn at openfirmware.info svn at openfirmware.info
Sun Jan 10 11:49:32 CET 2010


Author: wmb
Date: 2010-01-10 11:49:32 +0100 (Sun, 10 Jan 2010)
New Revision: 1657

Modified:
   ofw/fs/ext2fs/bitmap.fth
   ofw/fs/ext2fs/dir.fth
   ofw/fs/ext2fs/sb.fth
Log:
OLPC trac 9972 - fixed ext2 filesystem corruption that happened in
certain cases.  The problem was with the sparse superblock feature.
You must not write backup copies of the superblock and group descriptors
in every group when that feature is enabled.


Modified: ofw/fs/ext2fs/bitmap.fth
===================================================================
--- ofw/fs/ext2fs/bitmap.fth	2010-01-09 08:12:32 UTC (rev 1656)
+++ ofw/fs/ext2fs/bitmap.fth	2010-01-10 10:49:32 UTC (rev 1657)
@@ -164,10 +164,19 @@
 : update-gds   ( -- )
    gd-modified? if
       \ Copy group descriptors to backup locations
+      \ XXX if SPARSE_SUPER, then write only to groups 0,1, and powers of 3,5,7
+      \ One way to find out, other than checking the numbers, is to inspect
+      \ the block bitmap number in the group descriptor.  If it is larger than
+      \ the calculated block number, do the backup.
       #groups 1  do
-         0 group-desc		( gd0-adr )
-         i bpg *  2+ block	( gd0-adr gdn-adr )
-         bsize move update	( )
+         i bpg *  2+			( 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				( )
       loop
       false to gd-modified?
       update-sb

Modified: ofw/fs/ext2fs/dir.fth
===================================================================
--- ofw/fs/ext2fs/dir.fth	2010-01-09 08:12:32 UTC (rev 1656)
+++ ofw/fs/ext2fs/dir.fth	2010-01-10 10:49:32 UTC (rev 1657)
@@ -75,14 +75,13 @@
 : +link-count  ( increment -- )  link-count + link-count!  ;
 
 : new-inode    ( mode -- inode# )
-   alloc-inode set-inode
-   0 +i /inode erase		( mode )
+   alloc-inode set-inode        ( mode )   \ alloc-inode erases the inode
    file-attr!			( )
    time&date >unix-seconds	( time )
    dup atime!			( time ) \ set access time
    dup ctime!			( time ) \ set creation time
        mtime!			( )      \ set modification time
-   1 link-count!		( )      \ set links_count to 1
+   0 link-count!		( )      \ link count will be incremented by new-dirent
    inode#			( inode# )
 ;
 

Modified: ofw/fs/ext2fs/sb.fth
===================================================================
--- ofw/fs/ext2fs/sb.fth	2010-01-09 08:12:32 UTC (rev 1656)
+++ ofw/fs/ext2fs/sb.fth	2010-01-10 10:49:32 UTC (rev 1657)
@@ -28,6 +28,8 @@
 : fpg		( -- n )   9 +sbl  ;			\ h#2000 frags_per_group
 : ipg		( -- n )  10 +sbl  ;			\ h#790  inodes_per_group
 : magic         ( -- n )  28 +sbw  ;
+: state@        ( -- n )  29 +sbw  ;    \ for fsck: 0 for dirty, 1 for clean, 2 for known errors
+: state!        ( n -- )  super-block 29 wa+ short!  ;
 : revlevel	( -- n )  19 +sbl  ;
 : /inode        ( -- n )  revlevel 1 =  if  44 +sbw  else  h# 80  then  ;
 \ : bsize	( -- n )




More information about the openfirmware mailing list