From: David Zeuthen Date: Sun, 30 Mar 2008 18:38:29 +0000 (-0400) Subject: tell libparted to poke the kernel on partition table changes X-Git-Tag: upstream/2.1.2~1040 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef72505b1f87e8f23b78e6483336aeef34bf9ed2;p=platform%2Fupstream%2Fudisks2.git tell libparted to poke the kernel on partition table changes --- diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index c7cc1b6..f3dcb88 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -3024,11 +3024,13 @@ devkit_disks_device_delete_partition (DevkitDisksDevice *device, GError *error; char *offset_as_string; char *size_as_string; + char *part_number_as_string; PolKitCaller *pk_caller; DevkitDisksDevice *enclosing_device; offset_as_string = NULL; size_as_string = NULL; + part_number_as_string = NULL; if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL) goto out; @@ -3079,8 +3081,7 @@ devkit_disks_device_delete_partition (DevkitDisksDevice *device, offset_as_string = g_strdup_printf ("%lld", device->priv->info.partition_offset); size_as_string = g_strdup_printf ("%lld", device->priv->info.partition_size); - - /* TODO: options: quick, full, secure_gutmann_35pass etc. */ + part_number_as_string = g_strdup_printf ("%d", device->priv->info.partition_number); n = 0; argv[n++] = PACKAGE_LIBEXEC_DIR "/devkit-disks-helper-delete-partition"; @@ -3088,6 +3089,7 @@ devkit_disks_device_delete_partition (DevkitDisksDevice *device, argv[n++] = device->priv->info.device_file; argv[n++] = offset_as_string; argv[n++] = size_as_string; + argv[n++] = part_number_as_string; for (m = 0; options[m] != NULL; m++) { if (n >= (int) sizeof (argv) - 1) { throw_error (context, @@ -3117,6 +3119,7 @@ devkit_disks_device_delete_partition (DevkitDisksDevice *device, out: g_free (offset_as_string); g_free (size_as_string); + g_free (part_number_as_string); if (pk_caller != NULL) polkit_caller_unref (pk_caller); return TRUE; @@ -3753,10 +3756,12 @@ devkit_disks_device_create_partition (DevkitDisksDevice *device, PolKitCaller *pk_caller; char *offset_as_string; char *size_as_string; + char *max_number_as_string; char *flags_as_string; offset_as_string = NULL; size_as_string = NULL; + max_number_as_string = NULL; flags_as_string = NULL; if ((pk_caller = devkit_disks_damon_local_get_caller_for_context (device->priv->daemon, context)) == NULL) @@ -3793,6 +3798,7 @@ devkit_disks_device_create_partition (DevkitDisksDevice *device, offset_as_string = g_strdup_printf ("%lld", offset); size_as_string = g_strdup_printf ("%lld", size); + max_number_as_string = g_strdup_printf ("%d", device->priv->info.partition_table_max_number); /* TODO: check that neither of the flags include ',' */ flags_as_string = g_strjoinv (",", flags); @@ -3801,6 +3807,7 @@ devkit_disks_device_create_partition (DevkitDisksDevice *device, argv[n++] = device->priv->info.device_file;; argv[n++] = offset_as_string; argv[n++] = size_as_string; + argv[n++] = max_number_as_string; argv[n++] = (char *) type; argv[n++] = (char *) label; argv[n++] = (char *) flags_as_string; @@ -3833,6 +3840,7 @@ devkit_disks_device_create_partition (DevkitDisksDevice *device, out: g_free (offset_as_string); g_free (size_as_string); + g_free (max_number_as_string); g_free (flags_as_string); if (pk_caller != NULL) polkit_caller_unref (pk_caller); diff --git a/src/job-create-partition.c b/src/job-create-partition.c index d7b68bc..b939b95 100644 --- a/src/job-create-partition.c +++ b/src/job-create-partition.c @@ -44,7 +44,6 @@ int main (int argc, char **argv) { int n; - int fd; int ret; const char *device; char **options; @@ -57,11 +56,12 @@ main (int argc, char **argv) guint64 out_start; guint64 out_size; char *endp; + int max_number; ret = 1; flags = NULL; - if (argc < 7) { + if (argc < 8) { g_printerr ("wrong usage\n"); goto out; } @@ -76,10 +76,15 @@ main (int argc, char **argv) g_printerr ("malformed size '%s'\n", argv[3]); goto out; } - type = argv[4]; - label = argv[5]; - flags_as_string = argv[6]; - options = argv + 7; + max_number = strtol (argv[4], &endp, 10); + if (*endp != '\0') { + g_printerr ("malformed max number '%s'\n", argv[4]); + goto out; + } + type = argv[5]; + label = argv[6]; + flags_as_string = argv[7]; + options = argv + 8; flags = g_strsplit (flags_as_string, ",", 0); @@ -93,6 +98,7 @@ main (int argc, char **argv) g_print ("progress: %d %d -1 partitioning\n", 0, 2); + /* ask libparted to poke the kernel */ if (part_add_partition ((char *) device, offset, size, @@ -103,7 +109,8 @@ main (int argc, char **argv) flags, -1, -1, - FALSE)) { + TRUE)) { + /* now clear out file system signatures in the newly created * partition... Unless it's an extended partition! */ @@ -127,23 +134,6 @@ main (int argc, char **argv) g_printerr ("job-create-partition-size: %lld\n", out_size); } - /* TODO: replace blkrrpart with partx-ish ioctls */ - - /* either way, we've got this far.. signal the kernel to reread the partition table */ - fd = open (device, O_RDONLY); - if (fd < 0) { - g_printerr ("cannot open %s (for BLKRRPART): %m\n", device); - ret = 1; - goto out; - } - - if (ioctl (fd, BLKRRPART) != 0) { - close (fd); - g_printerr ("BLKRRPART ioctl failed for %s: %m\n", device); - ret = 1; - goto out; - } - close (fd); out: g_strfreev (flags); diff --git a/src/job-delete-partition.c b/src/job-delete-partition.c index f36cbf8..ef1ca4f 100644 --- a/src/job-delete-partition.c +++ b/src/job-delete-partition.c @@ -43,7 +43,6 @@ int main (int argc, char **argv) { - int fd; int ret; const char *device; const char *partition_device; @@ -53,13 +52,14 @@ main (int argc, char **argv) int n; guint64 offset; guint64 size; + int part_number; char *endp; ret = 1; erase = NULL; - if (argc < 4) { + if (argc < 5) { g_printerr ("wrong usage\n"); goto out; } @@ -75,7 +75,13 @@ main (int argc, char **argv) g_printerr ("malformed size '%s'\n", argv[4]); goto out; } - options = argv + 5; + part_number = strtol (argv[5], &endp, 10); + if (*endp != '\0') { + g_printerr ("malformed partition number '%s'\n", argv[5]); + goto out; + } + + options = argv + 6; for (n = 0; options[n] != NULL; n++) { if (g_str_has_prefix (options[n], "erase=")) { @@ -94,7 +100,8 @@ main (int argc, char **argv) g_print ("progress: %d %d -1 partitioning\n", num_erase_passes, num_erase_passes + 2); - if (part_del_partition ((char *) device, offset, FALSE)) { + /* ask libparted to poke the kernel */ + if (part_del_partition ((char *) device, offset, TRUE)) { /* zero the contents of what was the _partition_ * @@ -108,24 +115,6 @@ main (int argc, char **argv) } } - /* TODO: replace blkrrpart with partx-ish ioctls */ - - /* either way, we've got this far.. signal the kernel to reread the partition table */ - fd = open (device, O_RDONLY); - if (fd < 0) { - g_printerr ("cannot open %s (for BLKRRPART): %m\n", device); - ret = 1; - goto out; - } - - if (ioctl (fd, BLKRRPART) != 0) { - close (fd); - g_printerr ("BLKRRPART ioctl failed for %s: %m\n", device); - ret = 1; - goto out; - } - close (fd); - out: g_free (erase); return ret;