]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (sun) use tt.c to list disk label
authorKarel Zak <kzak@redhat.com>
Thu, 2 May 2013 10:29:01 +0000 (12:29 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:54 +0000 (16:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisksunlabel.c
fdisks/fdisksunlabel.h

index 39380960d97da40a9825a5869fc190804dd0d50f..ff5a69c441d13df324cbf5bb143bdac36fb1a2bb 100644 (file)
@@ -676,8 +676,9 @@ static int sun_delete_partition(struct fdisk_context *cxt,
 static int sun_list_disklabel(struct fdisk_context *cxt)
 {
        struct sun_disklabel *sunlabel;
-       size_t i;
-       int w;
+       struct tt *tb = NULL;
+       size_t i, w;
+       int rc;
 
        assert(cxt);
        assert(cxt->label);
@@ -685,8 +686,6 @@ static int sun_list_disklabel(struct fdisk_context *cxt)
 
        sunlabel = self_disklabel(cxt);
 
-       w = strlen(cxt->dev_path);
-
        if (fdisk_context_display_details(cxt))
                fdisk_info(cxt,
                _("Label geometry: %d rpm, %d alternate and %d physical cylinders,\n"
@@ -701,33 +700,70 @@ static int sun_list_disklabel(struct fdisk_context *cxt)
                       sunlabel->label_id,
                       *sunlabel->vtoc.volume_id ? sunlabel->vtoc.volume_id : _("<none>"));
 
-       printf(_("%*s Flag    Start       End    Blocks   Id  System\n"),
-              w + 1, _("Device"));
+       tb = tt_new_table(TT_FL_FREEDATA);
+       if (!tb)
+               return -ENOMEM;
+
+       tt_define_column(tb, _("Device"), 0.2, 0);
+       tt_define_column(tb, _("Flag"),     2, TT_FL_RIGHT);
+       tt_define_column(tb, _("Start"),    9, TT_FL_RIGHT);
+       tt_define_column(tb, _("End"),      9, TT_FL_RIGHT);
+       /* TRANSLATORS: keep one blank space behind 'Blocks' */
+       tt_define_column(tb, _("Blocks "),  9, TT_FL_RIGHT);
+       tt_define_column(tb, _("Id"),       2, TT_FL_RIGHT);
+       tt_define_column(tb, _("System"), 0.2, TT_FL_TRUNC);
+
+       w = strlen(cxt->dev_path);
+
        for (i = 0 ; i < cxt->label->nparts_max; i++) {
                struct sun_partition *part = &sunlabel->partitions[i];
-               struct sun_info *info = &sunlabel->vtoc.infos[i];
-
-               if (part->num_sectors) {
-                       uint32_t start = be32_to_cpu(part->start_cylinder) * cxt->geom.heads * cxt->geom.sectors;
-                       uint32_t len = be32_to_cpu(part->num_sectors);
-                       struct fdisk_parttype *t = fdisk_get_partition_type(cxt, i);
-
-                       printf(
-                           "%s %c%c %9lu %9lu %9lu%c  %2x  %s\n",
-/* device */             partname(cxt->dev_path, i+1, w),
-/* flags */              be16_to_cpu(info->flags) & SUN_FLAG_UNMNT ? 'u' : ' ',
-                         be16_to_cpu(info->flags) & SUN_FLAG_RONLY ? 'r' : ' ',
-/* start */              (unsigned long) scround(cxt, start),
-/* end */                (unsigned long) scround(cxt, start+len),
-/* odd flag on end */    (unsigned long) len / 2, len & 1 ? '+' : ' ',
-/* type id */            t->type,
-/* type name */                  t->name);
-
-                       fdisk_free_parttype(t);
-               }
+               uint16_t flags = be16_to_cpu(sunlabel->vtoc.infos[i].flags);
+               uint32_t start, len;
+               struct fdisk_parttype *t;
+               struct tt_line *ln;
+               char *p;
+
+               if (!part->num_sectors)
+                       continue;
+               ln = tt_add_line(tb, NULL);
+               if (!ln)
+                       continue;
+
+               start = be32_to_cpu(part->start_cylinder)
+                               * cxt->geom.heads
+                               * cxt->geom.sectors;
+
+               len = be32_to_cpu(part->num_sectors);
+               t = fdisk_get_partition_type(cxt, i);
+
+               p = partname(cxt->dev_path, i+1, w);
+               if (p)
+                       tt_line_set_data(ln, 0, strdup(p));     /* devname */
+               if ((flags & SUN_FLAG_UNMNT || flags & SUN_FLAG_RONLY)
+                   && asprintf(&p, "%c%c",
+                               flags & SUN_FLAG_UNMNT ? 'u' : ' ',
+                               flags & SUN_FLAG_RONLY ? 'r' : ' ') > 0)
+                       tt_line_set_data(ln, 1, p);     /* flags */
+               if (asprintf(&p, "%lu", scround(cxt, start)) > 0)
+                       tt_line_set_data(ln, 2, p);     /* start */
+               if (asprintf(&p, "%lu", scround(cxt, start + len)) > 0)
+                       tt_line_set_data(ln, 3, p);     /* end */
+               if (asprintf(&p, "%lu%c",
+                               (unsigned long) len / 2,
+                               len & 1 ? '+' : ' ') > 0)
+                       tt_line_set_data(ln, 4, p);     /* blocks + flag */
+               if (asprintf(&p, "%2x", t->type) > 0)
+                       tt_line_set_data(ln, 5, p);     /* type ID */
+               if (t->name)
+                       tt_line_set_data(ln, 6, strdup(t->name)); /* type Name */
+
+               fdisk_free_parttype(t);
        }
 
-       return 0;
+       rc = fdisk_print_table(cxt, tb);
+       tt_free_table(tb);
+
+       return rc;
 }
 
 
index 9487be3c793c67976707448b4f8eb155ee58c30e..f973725d3aadc2c4b5eb88d2e78594fcae6d4647 100644 (file)
@@ -11,7 +11,4 @@ extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
 extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
 extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
 
-/* fdisksunlabel.c */
-extern void sun_list_table(struct fdisk_context *cxt, int xtra);
-
 #endif /* FDISK_SUN_LABEL_H */