]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use fdisk_reread_changes()
authorKarel Zak <kzak@redhat.com>
Fri, 14 Jul 2017 09:08:54 +0000 (11:08 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 14 Jul 2017 09:34:55 +0000 (11:34 +0200)
Let's make fdisk usable for disks where some partitions are mounted.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk-menu.c
disk-utils/fdisk.c
disk-utils/fdisk.h

index 9245bac8a0998ff17d0584fdea9b699ad483acf3..8ad0fc1a59b93606c2b0482ba0039797f1723352 100644 (file)
@@ -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 */
index 56c8d63ac29c6819768ab0e10effd9f2558e9760..e8311bc016618300c4e97c7284618cc10ac2081a 100644 (file)
@@ -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 <columns> */
 
+               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);
        }
index 8c08bc34d240eea021fea01fde64ae692502d21d..f738fa478a52d72f107655ff0f42a7388d635ff3 100644 (file)
@@ -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)