From 6e62e3de91372558b13ebbdf45fe74441411cffa Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Sat, 22 Mar 2008 02:17:47 -0400 Subject: [PATCH] if creating a fs on the main device, signal kernel to reread partition table --- src/devkit-disks-device.c | 1 + src/job-mkfs.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index 3969f2b..7d79352 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -2550,6 +2550,7 @@ devkit_disks_device_create_filesystem_internal (DevkitDisksDevice *device, argv[n++] = PACKAGE_LIBEXEC_DIR "/devkit-disks-helper-mkfs"; argv[n++] = (char *) fstype; argv[n++] = device->priv->info.device_file; + argv[n++] = device->priv->info.device_is_partition_table ? "1" : "0"; for (m = 0; options[m] != NULL; m++) { if (n >= (int) sizeof (argv) - 1) { throw_error (context, diff --git a/src/job-mkfs.c b/src/job-mkfs.c index b9aa540..59794d4 100644 --- a/src/job-mkfs.c +++ b/src/job-mkfs.c @@ -73,6 +73,7 @@ out: int main (int argc, char **argv) { + int fd; int ret; int exit_status; GError *error; @@ -86,25 +87,28 @@ main (int argc, char **argv) char *erase; int num_erase_passes; int n; + gboolean is_kernel_partitioned; ret = 1; command_line = NULL; standard_error = NULL; erase = NULL; - if (argc < 3) { + if (argc < 4) { g_printerr ("wrong usage\n"); goto out; } fstype = argv[1]; device = argv[2]; - options = argv + 3; + is_kernel_partitioned = (strcmp (argv[3], "1") == 0); + options = argv + 4; /* TODO: clean out metadata in start and beginning */ if (strcmp (fstype, "vfat") == 0) { - s = g_string_new ("mkfs.vfat"); + /* allow to create an fs on the main block device */ + s = g_string_new ("mkfs.vfat -I"); for (n = 0; options[n] != NULL; n++) { if (g_str_has_prefix (options[n], "label=")) { label = strdup (options[n] + sizeof ("label=") - 1); @@ -226,6 +230,25 @@ main (int argc, char **argv) } } + /* If we've created an fs on a partitioned device, then signal the + * kernel to reread the (now missing) partition table. + */ + if (is_kernel_partitioned) { + 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); + } + ret = 0; out: -- 2.7.4