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/fdisk.c | |
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/fdisk.c')
-rw-r--r-- | disk-utils/fdisk.c | 44 |
1 files changed, 44 insertions, 0 deletions
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; |