From mboxrd@z Thu Jan 1 00:00:00 1970 From: Josh Glover Subject: [PATCH] '-b superblock' flag for tune2fs Date: Sat, 22 Mar 2003 13:39:21 -0500 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20030322183921.GF24720@harp.incogen.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TD8GDToEDw0WLGOL" Return-path: To: linux-fsdevel@vger.kernel.org Content-Disposition: inline List-Id: linux-fsdevel.vger.kernel.org --TD8GDToEDw0WLGOL Content-Type: multipart/mixed; boundary="k4f25fnPtRuIRUb3" Content-Disposition: inline --k4f25fnPtRuIRUb3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =20 --=20 Josh Glover 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 --k4f25fnPtRuIRUb3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="e2fsprogs-1.32_tune2fs_alt-superblock.patch" Content-Transfer-Encoding: quoted-printable diff -uNr e2fsprogs-1.32/misc/tune2fs.8.in 0_JMGLOV_e2fsprogs-1.32/misc/tun= e2fs.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 filesyste= m. .SH OPTIONS .TP +.BI \-b " superblock" +Instead of using the normal superblock, use an alternative superblock +specified by=20 +.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. =20 +.IP +Additional backup superblocks can be determined by using the=20 +.B mke2fs=20 +program using the=20 +.B \-n +option to print out where the superblocks were created. The=20 +.B \-b=20 +option to=20 +.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 =20 +the filesystem is not opened read-only, e2fsck will make sure that the +primary superblock is updated appropriately upon completion of the=20 +filesystem check. +.TP .BI \-c " max-mount-counts" Adjust the maximal mounts count between two filesystem checks. If=20 .I max-mount-counts diff -uNr e2fsprogs-1.32/misc/tune2fs.c 0_JMGLOV_e2fsprogs-1.32/misc/tune2f= s.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 -0= 500 @@ -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 =3D -1, u_flag, U_flag, T_flag; +static int b_flag =3D 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; =20 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); - while ((c =3D getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) = !=3D EOF) + while ((c =3D getopt(argc, argv, "b:c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")= ) !=3D EOF) switch (c) { + case 'b': + b_flag =3D atoi(optarg); + break; case 'c': max_mount_count =3D strtol (optarg, &tmp, 0); if (*tmp || max_mount_count > 16000) { @@ -712,15 +715,27 @@ else parse_tune2fs_options(argc, argv); =09 - retval =3D 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 =3D EXT2_MIN_BLOCK_SIZE; + blocksize <=3D EXT2_MAX_BLOCK_SIZE; blocksize *=3D 2) { + retval =3D ext2fs_open (device_name, open_flag, b_flag, blocksize, + unix_io_manager, &fs); + if (!retval) + break; + } + } else { + retval =3D 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); + } + } + =20 sb =3D fs->super; if (print_label) { /* For e2label emulation */ --k4f25fnPtRuIRUb3-- --TD8GDToEDw0WLGOL Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+fK3ZqGfbsWI4aWcRAjgAAJ4wc0TBy7p5PnAlQWMrrQG3uyAxlgCfQeHf ESvalegAcxknGXtFjBk+8J8= =jL3C -----END PGP SIGNATURE----- --TD8GDToEDw0WLGOL--