]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add partitions reorder operation to label API
authorKarel Zak <kzak@redhat.com>
Fri, 18 Apr 2014 11:26:08 +0000 (13:26 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 18 Apr 2014 11:26:08 +0000 (13:26 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk-menu.c
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/label.c
libfdisk/src/libfdisk.h

index bdaa7347552aa0bbe5541c5128ebc278fca70a70..4e44f0b854e3ed91720b205795be795be3b565c6 100644 (file)
@@ -102,6 +102,7 @@ struct menu menu_generic = {
 
                MENU_XENT('d', N_("print the raw data of the first sector from the device")),
                MENU_XENT('D', N_("print the raw data of the disklabel from the device")),
+               MENU_XENT('f', N_("fix partitions order")),
 
                MENU_SEP(N_("Misc")),
                MENU_BENT ('m', N_("print this menu")),
@@ -210,7 +211,6 @@ struct menu menu_dos = {
                MENU_ENT('c', N_("toggle the dos compatibility flag")),
 
                MENU_XENT('b', N_("move beginning of data in a partition")),
-               MENU_XENT('f', N_("fix partition order")),
                MENU_XENT('i', N_("change the disk identifier")),
 
                MENU_XENT_NEST('M', N_("return from protective/hybrid MBR to GPT"),
@@ -482,6 +482,9 @@ static int generic_menu_cb(struct fdisk_context **cxt0,
                case 'D':
                        dump_disklabel(cxt);
                        break;
+               case 'f':
+                       rc = fdisk_reorder_partitions(cxt);
+                       break;
                case 'r':
                        rc = fdisk_context_enable_details(cxt, 0);
                        break;
@@ -658,9 +661,6 @@ static int dos_menu_cb(struct fdisk_context **cxt0,
                        rc = fdisk_dos_move_begin(cxt, n);
                break;
        }
-       case 'f':
-               rc = fdisk_dos_fix_order(cxt);
-               break;
        case 'i':
                rc = fdisk_set_disklabel_id(cxt);
                break;
index b68765bb10d5d9d4dc8452e77db03ef907440c5c..645410cbd434f2f9e3137933f99445961857ab7f 100644 (file)
@@ -1803,7 +1803,7 @@ again:
        DBG(LABEL, print_chain_of_logicals(cxt));
 }
 
-int fdisk_dos_fix_order(struct fdisk_context *cxt)
+static int dos_reorder(struct fdisk_context *cxt)
 {
        struct pte *pei, *pek;
        size_t i,k;
@@ -1990,6 +1990,7 @@ static const struct fdisk_label_operations dos_operations =
        .create         = dos_create_disklabel,
        .locate         = dos_locate_disklabel,
        .list           = dos_list_disklabel,
+       .reorder        = dos_reorder,
        .get_id         = dos_get_disklabel_id,
        .set_id         = dos_set_disklabel_id,
 
index f966d0a68519d6745faece38f21af8b580653224..f5b4bb8edb40414f95a98e1b613e6de1d5605bb4 100644 (file)
@@ -182,10 +182,12 @@ struct fdisk_label_operations {
        int (*verify)(struct fdisk_context *cxt);
        /* create new disk label */
        int (*create)(struct fdisk_context *cxt);
-       /* list partition table */
+       /* list disklabel details */
        int (*list)(struct fdisk_context *cxt);
        /* returns offset and size of the 'n' part of the PT */
        int (*locate)(struct fdisk_context *cxt, int n, const char **name, off_t *offset, size_t *size);
+       /* reorder partitions */
+       int (*reorder)(struct fdisk_context *cxt);
 
        /* get disk label ID */
        int (*get_id)(struct fdisk_context *cxt, char **id);
index 9c6fcc5b38bd64f33effdc7553c4f8aaac82fca3..3881a2713731a74a2962d77ca8ddb6e6531ed4f3 100644 (file)
@@ -372,6 +372,24 @@ int fdisk_partition_toggle_flag(struct fdisk_context *cxt,
        return rc;
 }
 
+/**
+ * fdisk_reorder_partitions
+ * @cxt: fdisk context
+ *
+ * Sort partitions according to the partition start sector.
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_reorder_partitions(struct fdisk_context *cxt)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->op->reorder)
+               return -ENOSYS;
+
+       return cxt->label->op->reorder(cxt);
+}
+
 /*
  * Resets the current used label driver to initial state
  */
index b44451da611214e0e6c27be5b9f61c3aeae26d20..4143d9bc34843328a82204aa51fea28e6314a698 100644 (file)
@@ -224,6 +224,8 @@ extern int fdisk_partition_end_follow_default(struct fdisk_partition *pa, int en
 
 extern int fdisk_dump_partition(struct fdisk_partition *pa, FILE *f);
 
+extern int fdisk_reorder_partitions(struct fdisk_context *cxt);
+
 /* table.c */
 extern struct fdisk_table *fdisk_new_table(void);
 extern int fdisk_reset_table(struct fdisk_table *tb);
@@ -324,7 +326,6 @@ extern struct dos_partition *fdisk_dos_get_partition(
                                struct fdisk_context *cxt,
                                size_t i);
 
-extern int fdisk_dos_fix_order(struct fdisk_context *cxt);
 extern int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i);
 
 #define DOS_FLAG_ACTIVE        1