]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (dos) move list table code to fdiskdoslabe.c
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jan 2013 11:01:44 +0000 (12:01 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 11:47:30 +0000 (12:47 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskdoslabel.c
fdisks/fdiskdoslabel.h

index 58b945281b2e397ec15496b6d1eb0ae934c1c223..ee4c3ca07f73cf033ba5b8ced63b1b310f4b1854 100644 (file)
@@ -176,20 +176,6 @@ get_part_table(int i) {
        return ptes[i].part_table;
 }
 
-static int
-is_garbage_table(void) {
-       int i;
-
-       for (i = 0; i < 4; i++) {
-               struct pte *pe = &ptes[i];
-               struct partition *p = pe->part_table;
-
-               if (p->boot_ind != 0 && p->boot_ind != 0x80)
-                       return 1;
-       }
-       return 0;
-}
-
 void print_menu(struct fdisk_context *cxt, enum menutype menu)
 {
        size_t i;
@@ -813,7 +799,7 @@ list_disk_geometry(struct fdisk_context *cxt) {
  * Return 0 if OK. Return i if partition i should have been earlier.
  * Two separate checks: primary and logical partitions.
  */
-static int
+int
 wrong_p_order(int *prev) {
        struct pte *pe;
        struct partition *p;
@@ -945,9 +931,6 @@ fix_partition_table_order(void) {
 
 static void list_table(struct fdisk_context *cxt, int xtra)
 {
-       struct partition *p;
-       int i, w;
-
        if (fdisk_is_disklabel(cxt, SUN)) {
                sun_list_table(cxt, xtra);
                return;
@@ -970,62 +953,8 @@ static void list_table(struct fdisk_context *cxt, int xtra)
                return;
        }
 
-       if (is_garbage_table()) {
-               printf(_("This doesn't look like a partition table\n"
-                        "Probably you selected the wrong device.\n\n"));
-       }
-
-       /* Heuristic: we list partition 3 of /dev/foo as /dev/foo3,
-          but if the device name ends in a digit, say /dev/foo1,
-          then the partition is called /dev/foo1p3. */
-       w = strlen(cxt->dev_path);
-       if (w && isdigit(cxt->dev_path[w-1]))
-               w++;
-       if (w < 5)
-               w = 5;
-
-       printf(_("%*s Boot      Start         End      Blocks   Id  System\n"),
-              w+1, _("Device"));
-
-       for (i = 0; i < partitions; i++) {
-               struct pte *pe = &ptes[i];
-
-               p = pe->part_table;
-               if (p && !is_cleared_partition(p)) {
-                       unsigned int psects = get_nr_sects(p);
-                       unsigned int pblocks = psects;
-                       unsigned int podd = 0;
-                       struct fdisk_parttype *type =
-                                       fdisk_get_parttype_from_code(cxt, p->sys_ind);
-
-                       if (cxt->sector_size < 1024) {
-                               pblocks /= (1024 / cxt->sector_size);
-                               podd = psects % (1024 / cxt->sector_size);
-                       }
-                       if (cxt->sector_size > 1024)
-                               pblocks *= (cxt->sector_size / 1024);
-                        printf(
-                           "%s  %c %11lu %11lu %11lu%c  %2x  %s\n",
-                       partname(cxt->dev_path, i+1, w+2),
-/* boot flag */                !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG
-                       ? '*' : '?',
-/* start */            (unsigned long) cround(get_partition_start(pe)),
-/* end */              (unsigned long) cround(get_partition_start(pe) + psects
-                               - (psects ? 1 : 0)),
-/* odd flag on end */  (unsigned long) pblocks, podd ? '+' : ' ',
-/* type id */          p->sys_ind,
-/* type name */                type ? type->name : _("Unknown"));
-                       check_consistency(cxt, p, i);
-                       fdisk_warn_alignment(cxt, get_partition_start(pe), i);
-               }
-       }
-
-       /* Is partition table in disk order? It need not be, but... */
-       /* partition table entries are not checked for correct order if this
-          is a sgi, sun or aix labeled disk... */
-       if (fdisk_is_disklabel(cxt, DOS) && wrong_p_order(NULL)) {
-               printf(_("\nPartition table entries are not in disk order\n"));
-       }
+       if (fdisk_is_disklabel(cxt, DOS))
+               dos_list_table(cxt, xtra);
 }
 
 static void
index ae9d3a127962a36324d402395b272703be9ee237..0217bdfd47d8fed884a95a873eb79578f1287edd 100644 (file)
@@ -93,6 +93,8 @@ extern unsigned int read_int_with_suffix(struct fdisk_context *cxt,
                                  unsigned int base, char *mesg, int *is_suffix_used);
 extern int get_partition_dflt(struct fdisk_context *cxt, int warn, int max, int dflt);
 
+extern int wrong_p_order(int *prev);
+
 #define PLURAL 0
 #define SINGULAR 1
 extern const char * str_units(int);
index 3a3b710184dfd3738c7c4933d3196aa8acf9c51c..da6526e3fe0df622cf8c0af0a614511877e2857e 100644 (file)
@@ -964,6 +964,91 @@ static int dos_set_parttype(
        return 0;
 }
 
+
+static int is_garbage_table(void)
+{
+       int i;
+
+       for (i = 0; i < 4; i++) {
+               struct pte *pe = &ptes[i];
+               struct partition *p = pe->part_table;
+
+               if (p->boot_ind != 0 && p->boot_ind != 0x80)
+                       return 1;
+       }
+       return 0;
+}
+
+int dos_list_table(struct fdisk_context *cxt,
+                   int xtra  __attribute__ ((__unused__)))
+{
+       struct partition *p;
+       int i, w;
+
+       assert(cxt);
+       assert(fdisk_is_disklabel(cxt, DOS));
+
+       if (is_garbage_table()) {
+               printf(_("This doesn't look like a partition table\n"
+                        "Probably you selected the wrong device.\n\n"));
+       }
+
+       /* Heuristic: we list partition 3 of /dev/foo as /dev/foo3,
+          but if the device name ends in a digit, say /dev/foo1,
+          then the partition is called /dev/foo1p3. */
+       w = strlen(cxt->dev_path);
+       if (w && isdigit(cxt->dev_path[w-1]))
+               w++;
+       if (w < 5)
+               w = 5;
+
+       printf(_("%*s Boot      Start         End      Blocks   Id  System\n"),
+              w+1, _("Device"));
+
+       for (i = 0; i < partitions; i++) {
+               struct pte *pe = &ptes[i];
+
+               p = pe->part_table;
+               if (p && !is_cleared_partition(p)) {
+                       unsigned int psects = get_nr_sects(p);
+                       unsigned int pblocks = psects;
+                       unsigned int podd = 0;
+                       struct fdisk_parttype *type =
+                                       fdisk_get_parttype_from_code(cxt, p->sys_ind);
+
+                       if (cxt->sector_size < 1024) {
+                               pblocks /= (1024 / cxt->sector_size);
+                               podd = psects % (1024 / cxt->sector_size);
+                       }
+                       if (cxt->sector_size > 1024)
+                               pblocks *= (cxt->sector_size / 1024);
+                        printf(
+                           "%s  %c %11lu %11lu %11lu%c  %2x  %s\n",
+                       partname(cxt->dev_path, i+1, w+2),
+/* boot flag */                !p->boot_ind ? ' ' : p->boot_ind == ACTIVE_FLAG
+                       ? '*' : '?',
+/* start */            (unsigned long) cround(get_partition_start(pe)),
+/* end */              (unsigned long) cround(get_partition_start(pe) + psects
+                               - (psects ? 1 : 0)),
+/* odd flag on end */  (unsigned long) pblocks, podd ? '+' : ' ',
+/* type id */          p->sys_ind,
+/* type name */                type ? type->name : _("Unknown"));
+                       check_consistency(cxt, p, i);
+                       fdisk_warn_alignment(cxt, get_partition_start(pe), i);
+               }
+       }
+
+       /* Is partition table in disk order? It need not be, but... */
+       /* partition table entries are not checked for correct order if this
+          is a sgi, sun or aix labeled disk... */
+       if (wrong_p_order(NULL))
+               printf(_("\nPartition table entries are not in disk order\n"));
+
+       return 0;
+}
+
+
+
 static const struct fdisk_label_operations dos_operations =
 {
        .probe          = dos_probe_label,
index 41a253bb352ec1d771540545604e553168fc6347..cf20124ca68d249f883d289ce51f6a0a2505070d 100644 (file)
@@ -40,6 +40,8 @@ extern void dos_print_mbr_id(struct fdisk_context *cxt);
 extern void dos_set_mbr_id(struct fdisk_context *cxt);
 extern void dos_init(struct fdisk_context *cxt);
 
+extern int dos_list_table(struct fdisk_context *cxt, int xtra);
+
 extern int mbr_is_valid_magic(unsigned char *b);
 
 extern void change_units(struct fdisk_context *cxt);