From: Karel Zak Date: Fri, 18 Apr 2014 11:26:08 +0000 (+0200) Subject: libfdisk: add partitions reorder operation to label API X-Git-Tag: v2.25-rc1~261 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd7ba604631ce57f194f56dfb71414e42d914a21;p=thirdparty%2Futil-linux.git libfdisk: add partitions reorder operation to label API Signed-off-by: Karel Zak --- diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index bdaa734755..4e44f0b854 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -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; diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index b68765bb10..645410cbd4 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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, diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index f966d0a685..f5b4bb8edb 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -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); diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 9c6fcc5b38..3881a27137 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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 */ diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index b44451da61..4143d9bc34 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -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