[1/4]: Ext2/3 updates: Fix/simplify alternate superblock logic

[1/4]: Ext2/3 updates: Fix/simplify alternate superblock logic

Post by ty.. » Wed, 13 Nov 2002 08:40:05



Fix/simplify alternate superblock logic

Fix bugs when specifying an alternate superblock as a mount option; not
all of the cases where a alternate sb was specified and a block device
whose hardware blocksize was not 1024 worked correctly (and the failure
mode was different for ext2 and ext3).  The code has been tightened up
and simplified, so that it is right in all of the permutations of these
cases.

ext2/super.c |   12 +++++-------
ext3/super.c |   10 ++++------
2 files changed, 9 insertions(+), 13 deletions(-)

diff -Nru a/fs/ext2/super.c b/fs/ext2/super.c
--- a/fs/ext2/super.c   Tue Nov 12 01:12:15 2002

        struct buffer_head * bh;
        struct ext2_sb_info * sbi;
        struct ext2_super_block * es;
-       unsigned long block, sb_block = 1;
-       unsigned long logic_sb_block = get_sb_block(&data);
-       unsigned long offset = 0;
+       unsigned long block, sb_block = get_sb_block(&data);
+       unsigned long logic_sb_block;
+       unsigned long offset;
        unsigned long def_mount_opts;
        int blocksize = BLOCK_SIZE;

         * If the superblock doesn't start on a hardware sector boundary,
         * calculate the offset.  
         */
-       if (blocksize != BLOCK_SIZE) {
-               logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
-               offset = (sb_block*BLOCK_SIZE) % blocksize;
-       }
+       logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
+       offset = (sb_block*BLOCK_SIZE) % blocksize;

        if (!(bh = sb_bread(sb, logic_sb_block))) {
                printk ("EXT2-fs: unable to read superblock\n");
diff -Nru a/fs/ext3/super.c b/fs/ext3/super.c
--- a/fs/ext3/super.c   Tue Nov 12 01:12:15 2002

        struct ext3_super_block *es = 0;
        struct ext3_sb_info *sbi;
        unsigned long sb_block = get_sb_block(&data);
-       unsigned long block, logic_sb_block = 1;
-       unsigned long offset = 0;
+       unsigned long block, logic_sb_block;
+       unsigned long offset;
        unsigned long journal_inum = 0;
        unsigned long def_mount_opts;

         * The ext3 superblock will not be buffer aligned for other than 1kB
         * block sizes.  We need to calculate the offset from buffer start.
         */
-       if (blocksize != EXT3_MIN_BLOCK_SIZE) {
-               logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize;
-               offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize;
-       }
+       logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize;
+       offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize;

        if (!(bh = sb_bread(sb, logic_sb_block))) {
                printk (KERN_ERR "EXT3-fs: unable to read superblock\n");
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. finding alternate superblock on ext2 part'n

Dear all,
    Had a nasty partition corruption that killed the superblock. When I run
e2fsck


e2fsck 1.15, 18-Jul-1999 for EXT2 FS 0.5b, 95/08/09
Group descriptors look bad... trying backup blocks...
/sbin/e2fsck: Bad magic number in super-block while trying to open /dev/sdc8

The superblock could not be read or does not describe a correct ext2
filesystem.  If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>

Tried the address suggested but no go.
How can I find the address of the alternative superblock to fix this
The partition is over 2GB so the tool ext2ed doesnt work.

Andrew Gray

2. WTB Linux Journal Issue #3 (July 1994)

3. ext2/3 updates for 2.5.44 (1/11): Default mount options in superblock

4. Stack Trace?

5. acpi_wakeup.S: simplify logic

6. Sound problem: /dev/dsp: Out of memory

7. Bugs in LVM and ext2 + suggestion for fix (was: Problem mounting ext2 fs on LVM)

8. How do I compare non-integer values?

9. Strange fsck behaviour with alternated superblock

10. Kernel panic, alternate superblock

11. alternate superblock with UFS

12. Standard alternate superblock?

13. 2.0.33 Occasional space loss in ext2 filesystems - fixed by e2fsck - fix?