[PATCH] 12/13 e2fsprogs-findsuper - print per-sb info in findsuper

Andreas Dilger <[email protected]> Wed, 2 Aug 2006 11:01:53 -0600
Newsgroups gmane.comp.file-systems.ext2.devel
Message-ID <[email protected]>
Make it clearer which superblocks belong to the same filesystem by showing
part of the UUID and LABEL fields.

Show the byte offset of the start and end of the filesystem instead of the
block offset which was ambiguous and depended on the blocksize.

diff -rupwbB --exclude '.hg*' --exclude configure e2fsprogs/misc/findsuper.c e2fsprogs-lustre-hg/misc/findsuper.c
--- e2fsprogs/misc/findsuper.c	2006-04-05 01:48:42.000000000 -0600
+++ e2fsprogs-lustre-hg/misc/findsuper.c	2006-06-21 17:18:05.000000000 -0600
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 	if (sk < 0) {
-		fprintf(stderr,_("startkb should be positive, not %Ld\n"), sk);
+		fprintf(stderr, _("startkb should be positive, not %Lu\n"), sk);
 		exit(1);
 	}
 	fd = open(argv[1], O_RDONLY);
@@ -154,10 +154,14 @@ int main(int argc, char *argv[])
 	}
  
 	/* Now, go looking for the superblock! */
-	printf(_("starting at %Ld, with %d byte increments\n"), sk, skiprate);
-	printf(_("       thisoff     block fs_blk_sz  blksz grp last_mount\n"));
+	printf(_("starting at %Lu, with %u byte increments\n"), sk, skiprate);
+	printf(_("[*] likely a journal superblock, so start/end/grp wrong\n"));
+	printf(_("byte_offset  byte_start     byte_end  fs_blocks blksz  grp  last_mount_time           sb_uuid label\n"));
 	for (; lseek64(fd, sk, SEEK_SET) != -1 &&
 	       read(fd, &ext2, 512) == 512; sk += skiprate) {
+		static unsigned char last_uuid[16] = "blah";
+		unsigned long long bsize, grpsize;
+		int jnl_copy, sb_offset;
 
 		if (sk && !(sk & (interval - 1))) {
 			time_t now, diff;
@@ -168,7 +172,7 @@ int main(int argc, char *argv[])
 			if (diff > 0) {
 				s = ctime(&now);
 				s[24] = 0;
-				printf("\r%14Ld: %8LdkB/s @ %s", sk,
+				printf("\r%11Lu: %8LukB/s @ %s", sk,
 				       (((sk - skl)) / diff) >> 10, s);
 				fflush(stdout);
 			}
@@ -181,8 +185,8 @@ int main(int argc, char *argv[])
 		}
 		if (ext2.s_magic != EXT2_SUPER_MAGIC)
 			continue;
-		if (ext2.s_log_block_size > 4)
-			WHY("log block size > 4 (%u)\n", ext2.s_log_block_size);
+		if (ext2.s_log_block_size > 6)
+			WHY("log block size > 6 (%u)\n", ext2.s_log_block_size);
 		if (ext2.s_r_blocks_count > ext2.s_blocks_count)
 			WHY("r_blocks_count > blocks_count (%u > %u)\n",
 			    ext2.s_r_blocks_count, ext2.s_blocks_count);
@@ -196,12 +200,30 @@ int main(int argc, char *argv[])
 		tm = ext2.s_mtime;
 		s=ctime(&tm);
 		s[24]=0;
-		printf("\r%14Ld %9Ld %9d %5d %4d %s\n",
-		       sk, sk >> 10, ext2.s_blocks_count,
-		       1 << (ext2.s_log_block_size + 10),
-		       ext2.s_block_group_nr, s);
+		bsize = 1 << (ext2.s_log_block_size + 10);
+		grpsize = bsize * ext2.s_blocks_per_group;
+		if (memcmp(ext2.s_uuid, last_uuid, sizeof(last_uuid)) == 0 &&
+		    ext2.s_rev_level > 0 && ext2.s_block_group_nr == 0) {
+			jnl_copy = 1;
+		} else {
+			jnl_copy = 0;
+			memcpy(last_uuid, ext2.s_uuid, sizeof(last_uuid));
+		}
+		if (ext2.s_block_group_nr == 0 || bsize == 1024)
+			sb_offset = 1024;
+		else
+			sb_offset = 0;
+		printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %s\n",
+		       sk, sk - ext2.s_block_group_nr * grpsize - sb_offset,
+		       jnl_copy ? "*":" ",
+		       sk + ext2.s_blocks_count * bsize -
+		            ext2.s_block_group_nr * grpsize - sb_offset,
+		       jnl_copy ? "*" : " ", ext2.s_blocks_count, bsize,
+		       ext2.s_block_group_nr, jnl_copy ? "*" : " ", s,
+		       ext2.s_uuid[0], ext2.s_uuid[1],
+		       ext2.s_uuid[2], ext2.s_uuid[3], ext2.s_volume_name);
 	}
-	printf(_("\n%14Ld: finished with errno %d\n"), sk, errno);
+	printf(_("\n%11Lu: finished with errno %d\n"), sk, errno);
 	close(fd);
 
 	return errno;

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV