diff options
author | Jean-Loup 'clippix' Bogalho | 2015-05-09 23:15:23 +0200 |
---|---|---|
committer | Karel Zak | 2015-05-11 12:26:30 +0200 |
commit | 3e3b51b3b137a868a181f05c51edd7e9a5304ab3 (patch) | |
tree | 028c53415707ee9b860be0ec8dd159b0adf9ba37 /disk-utils | |
parent | tests: add hexdump from GPT (diff) | |
download | kernel-qcow2-util-linux-3e3b51b3b137a868a181f05c51edd7e9a5304ab3.tar.gz kernel-qcow2-util-linux-3e3b51b3b137a868a181f05c51edd7e9a5304ab3.tar.xz kernel-qcow2-util-linux-3e3b51b3b137a868a181f05c51edd7e9a5304ab3.zip |
fdisk: add the 'i'nfo command
Add the 'i'nfo command to fdisk that prints details about a specific partition.
Details are everything the function 'fdisk_label_get_field' can return.
Signed-off-by: Jean-Loup 'clippix' Bogalho <clippix@lse.epita.fr>
Diffstat (limited to 'disk-utils')
-rw-r--r-- | disk-utils/fdisk-menu.c | 4 | ||||
-rw-r--r-- | disk-utils/fdisk.c | 44 | ||||
-rw-r--r-- | disk-utils/fdisk.h | 2 |
3 files changed, 50 insertions, 0 deletions
diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index a77a13f80..6c7f58320 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -99,6 +99,7 @@ struct menu menu_generic = { MENU_BENT ('p', N_("print the partition table")), MENU_ENT ('t', N_("change a partition type")), MENU_BENT_E('v', N_("verify the partition table"), FDISK_DISKLABEL_BSD), + MENU_ENT ('i', N_("print information about a partition")), 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")), @@ -557,6 +558,9 @@ static int generic_menu_cb(struct fdisk_context **cxt0, case 'v': rc = fdisk_verify_disklabel(cxt); break; + case 'i': + rc = print_partition_info(cxt); + break; } /* expert mode */ diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index a1e7259bf..2b045743d 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -564,6 +564,50 @@ void change_partition_type(struct fdisk_context *cxt) fdisk_unref_partition(pa); } +int print_partition_info(struct fdisk_context *cxt) +{ + struct fdisk_partition *pa = NULL; + int rc = 0, details; + size_t i, nfields; + int *fields = NULL; + struct fdisk_label *lb = fdisk_get_label(cxt, NULL); + + if ((rc = fdisk_ask_partnum(cxt, &i, FALSE))) + return rc; + + if ((rc = fdisk_get_partition(cxt, i, &pa))) { + fdisk_warnx(cxt, _("Partition %zu does not exist yet!"), i + 1); + return rc; + } + + details = fdisk_is_details(cxt); + fdisk_enable_details(cxt, 1); + if ((rc = fdisk_label_get_fields_ids(lb, cxt, &fields, &nfields))) + goto clean_data; + fdisk_enable_details(cxt, details); + + for (i = 0; i < nfields; ++i) { + int id = fields[i]; + char *data = NULL; + const struct fdisk_field *fd = fdisk_label_get_field(lb, id); + + if (!fd) + continue; + + rc = fdisk_partition_to_string(pa, cxt, id, &data); + if (rc < 0) + goto clean_data; + + fdisk_info(cxt, _("%15s: %s"), fdisk_field_get_name(fd), data); + free(data); + } + +clean_data: + fdisk_unref_partition(pa); + free(fields); + return rc; +} + static size_t skip_empty(const unsigned char *buf, size_t i, size_t sz) { size_t next; diff --git a/disk-utils/fdisk.h b/disk-utils/fdisk.h index 4bd47339a..6a62c2497 100644 --- a/disk-utils/fdisk.h +++ b/disk-utils/fdisk.h @@ -36,6 +36,8 @@ extern int process_fdisk_menu(struct fdisk_context **cxt); extern int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask, void *data __attribute__((__unused__))); +extern int print_partition_info(struct fdisk_context *cxt); + /* prototypes for fdisk.c */ extern void dump_firstsector(struct fdisk_context *cxt); extern void dump_disklabel(struct fdisk_context *cxt); |