]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - libfdisk/src/sgi.c
libfdisk: remove dependence on libsmartcols
[thirdparty/util-linux.git] / libfdisk / src / sgi.c
index 19daf3ad460dcf0db67a4aa00a8e7d95ce9caca7..8e8d3208e1357f47be6c0c7418d4f243917f4a50 100644 (file)
@@ -10,6 +10,7 @@
  *               Arnaldo Carvalho de Melo <acme@conectiva.com.br>, Mar 1999,
  *               Phillip Kesling <pkesling@sgi.com>, Mar 2003.
  */
+
 #include "c.h"
 #include "nls.h"
 #include "all-io.h"
@@ -138,7 +139,7 @@ int fdisk_sgi_create_info(struct fdisk_context *cxt)
        sgilabel->volume[0].num_bytes = cpu_to_be32(sizeof(struct sgi_info));
        strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8);
 
-       fdisk_info(cxt, _("SGI info created on second sector"));
+       fdisk_info(cxt, _("SGI info created on second sector."));
        return 0;
 }
 
@@ -253,7 +254,7 @@ static int sgi_list_table(struct fdisk_context *cxt)
        int rc = 0;
 
        if (fdisk_context_display_details(cxt))
-               fdisk_colon(cxt, _(
+               fdisk_info(cxt, _(
                        "Label geometry: %d heads, %llu sectors\n"
                        "                %llu cylinders, %d physical cylinders\n"
                        "                %d extra sects/cyl, interleave %d:1\n"),
@@ -261,50 +262,7 @@ static int sgi_list_table(struct fdisk_context *cxt)
                        cxt->geom.cylinders, be16_to_cpu(sgiparam->pcylcount),
                        (int) sgiparam->sparecyl, be16_to_cpu(sgiparam->ilfact));
 
-#ifdef UNWANTED
-       char *p;
-       size_t i, used;
-       struct tt *tb = NULL;
-
-       /*
-        * Volumes
-        */
-       tb = tt_new_table(TT_FL_FREEDATA);
-       if (!tb)
-               return -ENOMEM;
-
-       tt_define_column(tb, _("#"),       3, TT_FL_RIGHT);
-       tt_define_column(tb, _("Name"),  0.2, 0);
-       tt_define_column(tb, _("Sector"),  2, TT_FL_RIGHT);
-       tt_define_column(tb, _("Size"),    9, TT_FL_RIGHT);
-
-       for (i = 0, used = 0; i < SGI_MAXVOLUMES; i++) {
-               struct tt_line *ln;
-               uint32_t start = be32_to_cpu(sgilabel->volume[i].block_num),
-                        len = be32_to_cpu(sgilabel->volume[i].num_bytes);
-               if (!len)
-                       continue;
-               ln = tt_add_line(tb, NULL);
-               if (!ln)
-                       continue;
-               if (asprintf(&p, "%zu:", i) > 0)
-                       tt_line_set_data(ln, 0, p);             /* # */
-               if (*sgilabel->volume[i].name)
-                       tt_line_set_data(ln, 1,
-                               strndup((char *) sgilabel->volume[i].name,
-                                       sizeof(sgilabel->volume[i].name)));     /* Name */
-               if (asprintf(&p, "%ju", (uintmax_t) start) > 0)
-                       tt_line_set_data(ln, 2, p);     /* Sector */
-               if (asprintf(&p, "%ju", (uintmax_t) len) > 0)
-                       tt_line_set_data(ln, 3, p);     /* Size */
-               used++;
-       }
-
-       if (used)
-               rc = fdisk_print_table(cxt, tb);
-       tt_free_table(tb);
-#endif
-       fdisk_colon(cxt, _("Bootfile: %s"), sgilabel->boot_file);
+       fdisk_info(cxt, _("Bootfile: %s"), sgilabel->boot_file);
        return rc;
 }
 
@@ -371,6 +329,9 @@ static int sgi_get_partition(struct fdisk_context *cxt, size_t n, struct fdisk_p
        pa->start = start;
        pa->end = start + len - (len ? 1 : 0);
 
+       if (pa->type && pa->type->type == SGI_TYPE_ENTIRE_DISK)
+               pa->wholedisk = 1;
+
        pa->attrs = sgi_get_swappartition(cxt) == (int) n ? "swap" :
                    sgi_get_bootpartition(cxt) == (int) n ? "boot" : NULL;
        if (pa->attrs)
@@ -607,14 +568,14 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
                                   sgi_get_start_sector(cxt, Index[0]));
 
                if (verbose && sgi_get_num_sectors(cxt, Index[0]) != lastblock)
-                       DBG(LABEL, dbgprint(
+                       DBG(LABEL, ul_debug(
                                "entire disk partition=%ds, but disk=%ds",
                                sgi_get_num_sectors(cxt, Index[0]),
                                lastblock));
                lastblock = sgi_get_num_sectors(cxt, Index[0]);
        } else if (verbose) {
                fdisk_info(cxt, _("Partition 11 should cover the entire disk."));
-               DBG(LABEL, dbgprint("sysid=%d\tpartition=%d",
+               DBG(LABEL, ul_debug("sysid=%d\tpartition=%d",
                               sgi_get_sysid(cxt, Index[0]), Index[0]+1));
        }
        for (i=1, start=0; i<sortcount; i++) {
@@ -622,12 +583,12 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
 
                if (verbose && cylsize
                    && (sgi_get_start_sector(cxt, Index[i]) % cylsize) != 0)
-                       DBG(LABEL, dbgprint("partition %d does not start on "
+                       DBG(LABEL, ul_debug("partition %d does not start on "
                                        "cylinder boundary.", Index[i]+1));
 
                if (verbose && cylsize
                    && sgi_get_num_sectors(cxt, Index[i]) % cylsize != 0)
-                       DBG(LABEL, dbgprint("partition %d does not end on "
+                       DBG(LABEL, ul_debug("partition %d does not end on "
                                        "cylinder boundary.", Index[i]+1));
 
                /* We cannot handle several "entire disk" entries. */
@@ -663,7 +624,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
                if (cylsize && start % cylsize)
                        start += cylsize - (start % cylsize);
 
-               DBG(LABEL, dbgprint("%2d:%12d\t%12d\t%12d", Index[i],
+               DBG(LABEL, ul_debug("%2d:%12d\t%12d\t%12d", Index[i],
                                       sgi_get_start_sector(cxt, Index[i]),
                                       sgi_get_num_sectors(cxt, Index[i]),
                                       sgi_get_sysid(cxt, Index[i])));
@@ -946,6 +907,7 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
 {
        struct fdisk_sgi_label *sgi;
        struct sgi_disklabel *sgilabel;
+       int rc;
 
        assert(cxt);
        assert(cxt->label);
@@ -974,7 +936,10 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
                }
        }
 #endif
-       fdisk_zeroize_firstsector(cxt);
+       rc = fdisk_init_firstsector_buffer(cxt);
+       if (rc)
+               return rc;
+
        sgi = (struct fdisk_sgi_label *) cxt->label;
        sgi->header = (struct sgi_disklabel *) cxt->firstsector;
 
@@ -1118,14 +1083,14 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign
 static const struct fdisk_column sgi_columns[] =
 {
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    TT_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    TT_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    TT_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    TT_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    TT_FL_RIGHT, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_TYPEID,     N_("Id"),         2,    TT_FL_RIGHT },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    TT_FL_TRUNC, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_ATTR,       N_("Attrs"),      0,    TT_FL_RIGHT }
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY },
+       { FDISK_COL_TYPEID,     N_("Id"),         2,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    FDISK_COLFL_EYECANDY },
+       { FDISK_COL_ATTR,       N_("Attrs"),      0,    FDISK_COLFL_NUMBER }
 };
 
 static const struct fdisk_label_operations sgi_operations =