From e2423cc07a0fafce4be50715336052eea4b9913a Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 18 Jun 1999 00:51:31 +0000 Subject: [PATCH] findsuper.c, ChangeLog: findsuper.c: Added documentation from aeb@cwi.nl; some minor code cleanups. --- misc/ChangeLog | 5 +++++ misc/findsuper.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index d3718b7..014db64 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,8 @@ +1999-05-02 + + * findsuper.c: Added documentation from aeb@cwi.nl; some minor + code cleanups. + 1999-05-20 * dumpe2fs.c, dumpe2fs.8.in: Added new command-line options which diff --git a/misc/findsuper.c b/misc/findsuper.c index 2a059f8..3a1ef3b 100644 --- a/misc/findsuper.c +++ b/misc/findsuper.c @@ -31,8 +31,38 @@ * Steve * ssd@nevets.oau.org * ssd@mae.engr.ucf.edu + * */ +/* + * Documentation addendum added by Andreas dwguest@win.tue.nl/aeb@cwi.nl + * + * The program findsuper is a utility that scans a disk and finds + * copies of ext2 superblocks (by checking for the ext2 signature; it + * will occasionally find other blocks that by coincidence have this + * signature - often these can be recognised by their ridiculous + * dates). + * + * For each superblock found, it prints the offset in bytes, the + * offset in 1024-byte blocks, the size of ext2 partition in 1024-byte + * blocks, the filesystem blocksize (given as log(blocksize)-10, so + * that 0 means 1024), the block group number (0 for older ext2 + * systems), and a timestamp (s_mtime). + * + * This program can be used to retrieve partitions that have been + * lost. The superblock for block group 0 is found 1 block (2 + * sectors) after the partition start. + * + * For new systems that have a block group number in the superblock it + * is immediately clear which superblock is the first of a partition. + * For old systems where no group numbers are given, the first + * superblock can be recognised by the timestamp: all superblock + * copies have the creation time in s_mtime, except the first, which + * has the last time e2fsck or tune2fs wrote to the filesystem. + * + */ + + #include #include #include @@ -82,15 +112,17 @@ main(int argc, char *argv[]) for (;!feof(f) && (i=fseek(f,sk,SEEK_SET))!= -1; sk+=skiprate){ if (i=fread(&ext2,sizeof(ext2),1, f)!=1) { perror("read failed"); - } else if (ext2.s_magic == EXT2_SUPER_MAGIC){ - tm = ext2.s_mtime; - s=ctime(&tm); - s[24]=0; - printf("%9ld %9ld %9ld %5ld %4d %s\n", sk, - sk/1024, ext2.s_blocks_count, - ext2.s_log_block_size, - ext2.s_block_group_nr, s); } + if (ext2.s_magic != EXT2_SUPER_MAGIC) + continue; + + tm = ext2.s_mtime; + s=ctime(&tm); + s[24]=0; + printf("%9ld %9ld %9ld %5ld %4d %s\n", sk, + sk/1024, ext2.s_blocks_count, + ext2.s_log_block_size, + ext2.s_block_group_nr, s); } printf("Failed on %d at %ld\n", i, sk); fclose(f); -- 1.8.3.1