Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Fwd: [PATCH] '-b superblock' flag for tune2fs



[ Just to toot my own horn... ;) ]


----- Forwarded message from Josh Glover <jmglov@example.com> -----

Date: Sat, 22 Mar 2003 13:39:21 -0500
From: Josh Glover <jmglov@example.com>
To: linux-fsdevel@example.com
Subject: [PATCH] '-b superblock' flag for tune2fs

I searched the archives of this list, as well as a general Google search,
and found nothing to suggest that this has been suggested and dismissed as
a bad idea, so here goes:

The attached patch adds the '-b superblock' flag to tune2fs. The flag works
exactly like the '-b superblock' flag to e2fsck:

-b superblock
       Instead  of  using  the  normal  superblock,  use an alternative
       superblock specified by superblock.   This  option  is  normally
       used  when the primary superblock has been corrupted.  The loca-
       tion of the backup superblock is dependent on  the  filesystem's
       blocksize.    For  filesystems  with  1k  blocksizes,  a  backup
       superblock can be found at block 8193; for filesystems  with  2k
       blocksizes,  at  block  16384;  and  for 4k blocksizes, at block
       32768.

       Additional backup superblocks can be  determined  by  using  the
       mke2fs  program  using  the  -n  option  to  print out where the
       superblocks were created.   The -b option to mke2fs, which spec-
       ifies blocksize of the filesystem must be specified in order for
       the superblock locations that are printed out to be accurate.

       If an alternative superblock is specified and the filesystem  is
       not  opened  read-only,  e2fsck  will make sure that the primary
       superblock is  updated  appropriately  upon  completion  of  the
       filesystem check.

So, you could run 'tune2fs -b 16384 -l /dev/hda1' on a filesystem with a
blocksize of 2K and a block group size of 16384 to look at the first of
the backup superblocks on the filesystem.

I found this flag to be useful, but YMMV, of course. As noted in the patch
filename, I generated the patch against version 1.32 of e2fsprogs.


Cheers,
Josh

       
-- 
Josh Glover <jmglov@example.com>

Associate Systems Administrator
INCOGEN, Inc.
http://www.incogen.com/

GPG keyID 0x62386967 (7479 1A7A 46E6 041D 67AE  2546 A867 DBB1 6238 6967)
gpg --keyserver pgp.mit.edu --recv-keys 62386967

diff -uNr e2fsprogs-1.32/misc/tune2fs.8.in 0_JMGLOV_e2fsprogs-1.32/misc/tune2fs.8.in
--- e2fsprogs-1.32/misc/tune2fs.8.in	2002-10-25 17:31:08.000000000 -0400
+++ 0_JMGLOV_e2fsprogs-1.32/misc/tune2fs.8.in	2003-03-22 13:13:05.000000000 -0500
@@ -8,6 +8,10 @@
 .SH SYNOPSIS
 .B tune2fs
 [
+.B \-b
+.I superblock
+]
+[
 .B \-l
 ]
 [
@@ -87,6 +91,32 @@
 adjusts tunable filesystem parameters on a Linux second extended filesystem.
 .SH OPTIONS
 .TP
+.BI \-b " superblock"
+Instead of using the normal superblock, use an alternative superblock
+specified by 
+.IR superblock .
+This option is normally used when the primary superblock has been
+corrupted.  The location of the backup superblock is dependent on the
+filesystem's blocksize.  For filesystems with 1k blocksizes, a backup
+superblock can be found at block 8193; for filesystems with 2k
+blocksizes, at block 16384; and for 4k blocksizes, at block 32768.  
+.IP
+Additional backup superblocks can be determined by using the 
+.B mke2fs 
+program using the 
+.B \-n
+option to print out where the superblocks were created.   The 
+.B \-b 
+option to 
+.BR mke2fs ,
+which specifies blocksize of the filesystem must be specified in order
+for the superblock locations that are printed out to be accurate.
+.IP
+If an alternative superblock is specified and  
+the filesystem is not opened read-only, e2fsck will make sure that the
+primary superblock is updated appropriately upon completion of the 
+filesystem check.
+.TP
 .BI \-c " max-mount-counts"
 Adjust the maximal mounts count between two filesystem checks.  If 
 .I max-mount-counts
diff -uNr e2fsprogs-1.32/misc/tune2fs.c 0_JMGLOV_e2fsprogs-1.32/misc/tune2fs.c
--- e2fsprogs-1.32/misc/tune2fs.c	2002-10-15 17:44:46.000000000 -0400
+++ 0_JMGLOV_e2fsprogs-1.32/misc/tune2fs.c	2003-03-22 13:06:56.000000000 -0500
@@ -58,6 +58,7 @@
 char * new_label, *new_last_mounted, *new_UUID;
 static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
 static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag;
+static int b_flag = 0;
 static time_t last_check_time;
 static int print_label;
 static int max_mount_count, mount_count, mount_flags;
@@ -78,9 +79,8 @@
 static void usage(void)
 {
 	fprintf(stderr,
-		_("Usage: %s [-c max-mounts-count] [-e errors-behavior] "
-		  "[-g group]\n"
-		  "\t[-i interval[d|m|w]] [-j] [-J journal-options]\n"
+		_("Usage: %s [-b superblock] [-c max-mounts-count] [-e errors-behavior]\n "
+		  "\t[-g group] [-i interval[d|m|w]] [-j] [-J journal-options]\n"
 		  "\t[-l] [-s sparse-flag] [-m reserved-blocks-percent]\n"
 		  "\t[-o [^]mount-options[,...]] [-r reserved-blocks-count]\n"
 		  "\t[-u user] [-C mount-count] [-L volume-label] "
@@ -462,9 +462,12 @@
 	struct passwd * pw;
 
 	printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
-	while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF)
+	while ((c = getopt(argc, argv, "b:c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF)
 		switch (c)
 		{
+      case 'b':
+				b_flag = atoi(optarg);
+        break;
 			case 'c':
 				max_mount_count = strtol (optarg, &tmp, 0);
 				if (*tmp || max_mount_count > 16000) {
@@ -712,15 +715,27 @@
 	else
 		parse_tune2fs_options(argc, argv);
 	
-	retval = ext2fs_open (device_name, open_flag, 0, 0,
-			      unix_io_manager, &fs);
-        if (retval) {
-		com_err (program_name, retval, _("while trying to open %s"),
-			 device_name);
-		fprintf(stderr,
-			_("Couldn't find valid filesystem superblock.\n"));
-		exit(1);
-	}
+  if (b_flag) {
+		int blocksize;
+		for (blocksize = EXT2_MIN_BLOCK_SIZE;
+		     blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
+			retval = ext2fs_open (device_name, open_flag, b_flag, blocksize,
+                            unix_io_manager, &fs);
+			if (!retval)
+				break;
+		}
+	} else {
+    retval = ext2fs_open (device_name, open_flag, 0, 0,
+                          unix_io_manager, &fs);
+    if (retval) {
+      com_err (program_name, retval, _("while trying to open %s"),
+               device_name);
+      fprintf(stderr,
+              _("Couldn't find valid filesystem superblock.\n"));
+      exit(1);
+    }
+  }
+  
 	sb = fs->super;
 	if (print_label) {
 		/* For e2label emulation */




----- End forwarded message -----

-- 
Josh Glover <jmglov@example.com>

Associate Systems Administrator
INCOGEN, Inc.
http://www.incogen.com/

GPG keyID 0x62386967 (7479 1A7A 46E6 041D 67AE  2546 A867 DBB1 6238 6967)
gpg --keyserver pgp.mit.edu --recv-keys 62386967

Attachment: pgp00014.pgp
Description: PGP signature


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links