]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
cmd_show_super: --field-only
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 5 Jan 2024 17:39:05 +0000 (12:39 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 5 Jan 2024 18:01:34 +0000 (13:01 -0500)
cmd_format.c

index 86bc59e9b8e6b7f59e89948fcc44981c813ce69c..45c44e3229d0f5ff50cf5b21d3bd6d1042267f1c 100644 (file)
@@ -305,6 +305,7 @@ static void show_super_usage(void)
             "\n"
             "Options:\n"
             "  -f, --fields=(fields)       list of sections to print\n"
+            "      --field-only=fiel)      print superblock section only, no header\n"
             "  -l, --layout                print superblock layout\n"
             "  -h, --help                  display this help and exit\n"
             "Report bugs to <linux-bcachefs@vger.kernel.org>");
@@ -315,11 +316,13 @@ int cmd_show_super(int argc, char *argv[])
 {
        static const struct option longopts[] = {
                { "fields",                     1, NULL, 'f' },
+               { "field-only",                 1, NULL, 'F' },
                { "layout",                     0, NULL, 'l' },
                { "help",                       0, NULL, 'h' },
                { NULL }
        };
        unsigned fields = 0;
+       int field_only = -1;
        bool print_layout = false;
        bool print_default_fields = true;
        int opt;
@@ -333,6 +336,11 @@ int cmd_show_super(int argc, char *argv[])
                                        bch2_sb_fields, "superblock field");
                        print_default_fields = false;
                        break;
+               case 'F':
+                       field_only = read_string_list_or_die(optarg,
+                                       bch2_sb_fields, "superblock field");
+                       print_default_fields = false;
+                       break;
                case 'l':
                        print_layout = true;
                        break;
@@ -369,7 +377,14 @@ int cmd_show_super(int argc, char *argv[])
 
        buf.human_readable_units = true;
 
-       bch2_sb_to_text(&buf, sb.sb, print_layout, fields);
+       if (field_only >= 0) {
+               struct bch_sb_field *f = bch2_sb_field_get_id(sb.sb, field_only);
+
+               if (f)
+                       __bch2_sb_field_to_text(&buf, sb.sb, f);
+       } else {
+               bch2_sb_to_text(&buf, sb.sb, print_layout, fields);
+       }
        printf("%s", buf.buf);
 
        bch2_free_super(&sb);