summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorKarel Zak2017-07-14 11:08:54 +0200
committerKarel Zak2017-07-14 11:34:55 +0200
commit044ebc0c93dba68b0063df4875e6fa2ce8e9e8e1 (patch)
treeeeefde7da13ce10d2d614d4e4fdeb7ecf1397953 /disk-utils
parentfdisk: use fdisk_reread_changes() (diff)
downloadkernel-qcow2-util-linux-044ebc0c93dba68b0063df4875e6fa2ce8e9e8e1.tar.gz
kernel-qcow2-util-linux-044ebc0c93dba68b0063df4875e6fa2ce8e9e8e1.tar.xz
kernel-qcow2-util-linux-044ebc0c93dba68b0063df4875e6fa2ce8e9e8e1.zip
cfdisk: use fdisk_reread_changes()
Let's make cfdisk usable for disks where some partitions are mounted. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/cfdisk.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 00c512e49..f14ae82a8 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -212,6 +212,7 @@ struct cfdisk_line {
struct cfdisk {
struct fdisk_context *cxt; /* libfdisk context */
struct fdisk_table *table; /* partition table */
+ struct fdisk_table *original_layout; /* original on-disk PT */
struct cfdisk_menu *menu; /* the current menu */
@@ -238,6 +239,7 @@ struct cfdisk {
#endif
unsigned int wrong_order :1, /* PT not in right order */
zero_start :1, /* ignore existing partition table */
+ device_is_used : 1, /* don't use re-read ioctl */
show_extra :1; /* show extra partinfo */
};
@@ -2371,7 +2373,10 @@ static int main_menu_action(struct cfdisk *cf, int key)
if (rc)
warn = _("Failed to write disklabel.");
else {
- fdisk_reread_partition_table(cf->cxt);
+ if (cf->device_is_used)
+ fdisk_reread_changes(cf->cxt, cf->original_layout);
+ else
+ fdisk_reread_partition_table(cf->cxt);
info = _("The partition table has been altered.");
}
cf->nwrites++;
@@ -2638,6 +2643,11 @@ int main(int argc, char *argv[])
if (rc != 0)
err(EXIT_FAILURE, _("cannot open %s"), diskpath);
+ if (!fdisk_is_readonly(cf->cxt)) {
+ cf->device_is_used = fdisk_device_is_used(cf->cxt);
+ fdisk_get_partitions(cf->cxt, &cf->original_layout);
+ }
+
/* Don't use err(), warn() from this point */
ui_init(cf);
ui_run(cf);