Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / misc / findsuper.c
index 5eade88..765295c 100644 (file)
@@ -6,7 +6,7 @@
  * using gpart program.
  *
  * Portions Copyright 1998-2000, Theodore Ts'o.
- * 
+ *
  * Well, here's my linux version of findsuper.
  * I'm sure you coulda done it faster.  :)
  * IMHO there isn't as much interesting data to print in the
@@ -18,7 +18,7 @@
  *
  * I wanted to add msdos support, but I couldn't make heads or tails
  * of the kernel include files to find anything I could look for in msdos.
- * 
+ *
  * Reading every block of a Sun partition is fairly quick.  Doing the
  * same under linux (slower hardware I suppose) just isn't the same.
  * It might be more useful to default to reading the first (second?) block
@@ -30,7 +30,7 @@
  *   findsuper /dev/hda
  *   findsuper /dev/hda 437760 1024   (my disk has cyls of 855*512)
  *
- * I suppose the next step is to figgure out a way to determine if
+ * I suppose the next step is to figure out a way to determine if
  * the block found is the first superblock somehow, and if so, build
  * a partition table from the superblocks found... but this is still
  * useful as is.
 
 /*
  * 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).
- * 
+ *
  * For each superblock found, it prints the offset in bytes, the
  * offset in 1024-byte blocks, the size of the ext2 partition in fs
  * blocks, the filesystem blocksize (in bytes), the block group number
  * (always 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
+ * superblock can be recognized 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.
- * 
+ *
  */
 
 #define _FILE_OFFSET_BITS 64
 
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -92,7 +93,8 @@
 #include <time.h>
 
 #include "ext2fs/ext2_fs.h"
-#include "nls-enable.h"
+#include "ext2fs/ext2fs.h"
+#include "support/nls-enable.h"
 
 #undef DEBUG
 
 #define WHY(fmt, arg...) { continue; }
 #endif
 
-static void usage(void) 
+static void usage(void)
 {
-       fprintf(stderr, 
+       fprintf(stderr,
                _("Usage:  findsuper device [skipbytes [startkb]]\n"));
        exit(1);
 }
@@ -129,6 +131,7 @@ int main(int argc, char *argv[])
        setlocale(LC_CTYPE, "");
        bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
        textdomain(NLS_CAT_NAME);
+       set_com_err_gettext(gettext);
 #endif
 
        while ((c = getopt (argc, argv, "j")) != EOF) {
@@ -169,10 +172,10 @@ int main(int argc, char *argv[])
                optind++;
        }
        if (sk < 0) {
-               fprintf(stderr, _("startkb should be positive, not %Lu\n"), sk);
+               fprintf(stderr, _("startkb should be positive, not %llu\n"),sk);
                exit(1);
        }
-       
+
        fd = open(device_name, O_RDONLY);
        if (fd < 0) {
                perror(device_name);
@@ -180,11 +183,11 @@ int main(int argc, char *argv[])
        }
 
        /* Now, go looking for the superblock! */
-       printf(_("starting at %Lu, with %u byte increments\n"), sk, skiprate);
+       printf(_("starting at %llu, with %u byte increments\n"), sk, skiprate);
        if (print_jnl_copies)
                printf(_("[*] probably superblock written in the ext3 "
                         "journal superblock,\n\tso start/end/grp wrong\n"));
-       printf(_("byte_offset  byte_start     byte_end  fs_blocks blksz  grp  last_mount_time           sb_uuid label\n"));
+       printf(_("byte_offset  byte_start     byte_end  fs_blocks blksz  grp  mkfs/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";
@@ -215,17 +218,22 @@ int main(int argc, char *argv[])
                        continue;
                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)
+               if (ext2fs_r_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
                        WHY("r_blocks_count > blocks_count (%u > %u)\n",
-                           ext2.s_r_blocks_count, ext2.s_blocks_count);
-               if (ext2.s_free_blocks_count > ext2.s_blocks_count)
+                           ext2fs_r_blocks_count(&ext2),
+                           ext2fs_blocks_count(&ext2));
+               if (ext2fs_free_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
                        WHY("free_blocks_count > blocks_count\n (%u > %u)\n",
-                           ext2.s_free_blocks_count, ext2.s_blocks_count);
+                           ext2fs_free_blocks_count(&ext2),
+                           ext2fs_blocks_count(&ext2));
                if (ext2.s_free_inodes_count > ext2.s_inodes_count)
                        WHY("free_inodes_count > inodes_count (%u > %u)\n",
                            ext2.s_free_inodes_count, ext2.s_inodes_count);
 
-               tm = ext2.s_mtime;
+               if (ext2.s_mkfs_time != 0)
+                       tm = ext2.s_mkfs_time;
+               else
+                       tm = ext2.s_mtime;
                s = ctime(&tm);
                s[24] = 0;
                bsize = 1 << (ext2.s_log_block_size + 10);
@@ -243,15 +251,16 @@ int main(int argc, char *argv[])
                        sb_offset = 0;
                if (jnl_copy && !print_jnl_copies)
                        continue;
-               printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %s\n",
+               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 -
+                      sk + ext2fs_blocks_count(&ext2) * bsize -
                            ext2.s_block_group_nr * grpsize - sb_offset,
-                      jnl_copy ? "*" : " ", ext2.s_blocks_count, bsize,
+                      jnl_copy ? "*" : " ", ext2fs_blocks_count(&ext2), 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);
+                      ext2.s_uuid[2], ext2.s_uuid[3],
+                      EXT2_LEN_STR(ext2.s_volume_name));
        }
        printf(_("\n%11Lu: finished with errno %d\n"), sk, errno);
        close(fd);