From fadd8e08774f872779690fa126b091d068f61d4d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 14 Jul 2017 11:08:54 +0200 Subject: fdisk: use fdisk_reread_changes() Let's make fdisk usable for disks where some partitions are mounted. Signed-off-by: Karel Zak --- disk-utils/fdisk-menu.c | 6 +++++- disk-utils/fdisk.c | 8 ++++++++ disk-utils/fdisk.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'disk-utils') diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index 9245bac8a..8ad0fc1a5 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -582,7 +582,11 @@ static int generic_menu_cb(struct fdisk_context **cxt0, if (fdisk_get_parent(cxt)) break; /* nested PT, don't leave */ fdisk_info(cxt, _("The partition table has been altered.")); - rc = fdisk_reread_partition_table(cxt); + + if (device_is_used) + rc = fdisk_reread_changes(cxt, original_layout); + else + rc = fdisk_reread_partition_table(cxt); if (!rc) rc = fdisk_deassign_device(cxt, 0); /* fallthrough */ diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 56c8d63ac..e8311bc01 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -52,6 +52,9 @@ #endif int pwipemode = WIPEMODE_AUTO; +int device_is_used; +struct fdisk_table *original_layout; + static int wipemode = WIPEMODE_AUTO; /* @@ -1036,6 +1039,11 @@ int main(int argc, char **argv) init_fields(cxt, outarg, NULL); /* -o */ + if (!fdisk_is_readonly(cxt)) { + fdisk_get_partitions(cxt, &original_layout); + device_is_used = fdisk_device_is_used(cxt); + } + while (1) process_fdisk_menu(&cxt); } diff --git a/disk-utils/fdisk.h b/disk-utils/fdisk.h index 8c08bc34d..f738fa478 100644 --- a/disk-utils/fdisk.h +++ b/disk-utils/fdisk.h @@ -25,6 +25,8 @@ #define FDISKPROG_DEBUG_ALL 0xFFFF extern int pwipemode; +extern struct fdisk_table *original_layout; +extern int device_is_used; UL_DEBUG_DECLARE_MASK(fdisk); #define DBG(m, x) __UL_DBG(fdisk, FDISKPROG_DEBUG_, m, x) -- cgit v1.2.3-55-g7522