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")),
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"),
case 'D':
dump_disklabel(cxt);
break;
+ case 'f':
+ rc = fdisk_reorder_partitions(cxt);
+ break;
case 'r':
rc = fdisk_context_enable_details(cxt, 0);
break;
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;
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;
.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,
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);
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
*/
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);
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