Whamcloud - gitweb
debugfs: Add support for "set_block_group <bg_num> checksum calc"
authorAndreas Dilger <adilger@dilger.ca>
Mon, 31 Mar 2008 00:05:12 +0000 (20:05 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 31 Mar 2008 18:28:26 +0000 (14:28 -0400)
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs/set_fields.c

index a58c94e..ee51c45 100644 (file)
@@ -42,6 +42,7 @@
 static struct ext2_super_block set_sb;
 static struct ext2_inode set_inode;
 static struct ext2_group_desc set_gd;
+static dgrp_t set_bg;
 static ext2_ino_t set_ino;
 static int array_idx;
 
@@ -63,6 +64,7 @@ static errcode_t parse_uuid(struct field_set_info *info, char *arg);
 static errcode_t parse_hashalg(struct field_set_info *info, char *arg);
 static errcode_t parse_time(struct field_set_info *info, char *arg);
 static errcode_t parse_bmap(struct field_set_info *info, char *arg);
+static errcode_t parse_gd_csum(struct field_set_info *info, char *arg);
 
 static struct field_set_info super_fields[] = {
        { "inodes_count", &set_sb.s_inodes_count, 4, parse_uint },
@@ -178,7 +180,7 @@ static struct field_set_info ext2_bg_fields[] = {
        { "flags", &set_gd.bg_flags, 2, parse_uint },
        { "reserved", &set_gd.bg_reserved, 2, parse_uint, FLAG_ARRAY, 2 },
        { "itable_unused", &set_gd.bg_itable_unused, 2, parse_uint },
-       { "checksum", &set_gd.bg_checksum, 2, parse_uint },
+       { "checksum", &set_gd.bg_checksum, 2, parse_gd_csum },
        { 0, 0, 0, 0 }
 };
 
@@ -402,6 +404,19 @@ static errcode_t parse_bmap(struct field_set_info *info, char *arg)
        return retval;
 }
 
+static errcode_t parse_gd_csum(struct field_set_info *info, char *arg)
+{
+
+       if (strcmp(arg, "calc") == 0) {
+               ext2fs_group_desc_csum_set(current_fs, set_bg);
+               set_gd = current_fs->group_desc[set_bg];
+               printf("Checksum set to 0x%04x\n", 
+                      current_fs->group_desc[set_bg].bg_checksum);
+               return 0;
+       }
+
+       return parse_uint(info, arg);
+}
 
 static void print_possible_fields(struct field_set_info *fields)
 {
@@ -521,7 +536,6 @@ void do_set_block_group_descriptor(int argc, char *argv[])
                "\t\"set_block_group_descriptor -l\" will list the names of "
                "the fields in a block group descriptor\n\twhich can be set.";
        struct field_set_info   *ss;
-       dgrp_t                  set_bg;
        char                    *end;
 
        if ((argc == 2) && !strcmp(argv[1], "-l")) {