diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2009-03-03 17:28:47 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2009-03-03 17:28:47 +0100 |
| commit | abc86e7f8afc79d102375cf7d60c2307cb5b52e8 (patch) | |
| tree | c6b09fa5c3a0a71f5e881022afa5f03c22574203 | |
| parent | 8e6bf7cf7d13c8734a5c469b2a3f96b974b34127 (diff) | |
| download | nautilus-gdu-abc86e7f8afc79d102375cf7d60c2307cb5b52e8.tar.gz nautilus-gdu-abc86e7f8afc79d102375cf7d60c2307cb5b52e8.tar.xz nautilus-gdu-abc86e7f8afc79d102375cf7d60c2307cb5b52e8.zip | |
Better handling of partition type change
| -rw-r--r-- | src/format-window-operation.c | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/src/format-window-operation.c b/src/format-window-operation.c index eec5c45..113a3e6 100644 --- a/src/format-window-operation.c +++ b/src/format-window-operation.c @@ -38,34 +38,6 @@ #define DEVICE_SETTLE_TIMEOUT 3000 -/* ---------------------------------------------------------------------------------------------------- */ - -/* TODO: this is quite dangerous, but needed */ -static const char * -get_part_type_for_fs (const char *fs_type) -{ - if (strcasecmp (fs_type, "vfat") == 0) - return "0x0c"; - else - if (strcasecmp (fs_type, "empty") == 0 || strlen (fs_type) == 0) - return "0x0"; - else - if (strcasecmp (fs_type, "ntfs") == 0) - return "0x07"; - else - if (strcasecmp (fs_type, "swap") == 0) - return "0x82"; - else - return "0x83"; /* default to "linux" */ -} - -static gboolean -mbr_part_is_linux_type (const char *part_type) -{ - return (strcasecmp (part_type, "0x83") == 0 || strcasecmp (part_type, "0x8e") == 0 || - strcasecmp (part_type, "0xfd") == 0); -} - /* Look whether the device needs to be partitioned */ /* - generally we don't want to have partitions on optical drives and floppy disks */ @@ -458,7 +430,8 @@ format_action_completed (GduDevice *device, { FormatProcessData *data = user_data; const char *part_type; - const char *scheme; + GduPresentable *toplevel_presentable; + GduDevice *toplevel_device; g_print ("format_action_completed\n"); g_return_if_fail (data != NULL); @@ -472,16 +445,26 @@ format_action_completed (GduDevice *device, } else { - scheme = gdu_device_partition_get_scheme (device); -// g_print ("format_action_completed: scheme = %s\n", scheme); - /* TODO: extend to other partition types once this feature is working in DK */ - if (! data->priv->job_cancelled && strcmp (scheme, "mbr") == 0) { + /* Get device scheme if needed */ + if (! data->scheme || strlen (data->scheme) == 0) { + toplevel_presentable = gdu_presentable_get_toplevel (data->presentable); + if (toplevel_presentable) { + toplevel_device = gdu_presentable_get_device (toplevel_presentable); + if (toplevel_device) { + data->scheme = gdu_device_partition_table_get_scheme (toplevel_device); + g_object_unref (toplevel_device); + } + g_object_unref (toplevel_presentable); + } + } + + /* Correct partition type */ + if (! data->priv->job_cancelled && data->scheme && strlen (data->scheme) > 0) { part_type = gdu_device_partition_get_type (device); - data->recommended_part_type = get_part_type_for_fs (data->fstype); + data->recommended_part_type = gdu_util_get_default_part_type_for_scheme_and_fstype (data->scheme, data->fstype, gdu_device_partition_get_size (device)); g_print ("format_action_completed: part_type = %s, recommended_part_type = %s\n", part_type, data->recommended_part_type); /* Change partition type if necessary */ - if (strcasecmp (part_type, data->recommended_part_type) != 0 && - ! (mbr_part_is_linux_type (part_type) && mbr_part_is_linux_type (data->recommended_part_type))) + if (strcasecmp (part_type, data->recommended_part_type) != 0) { g_print ("changing part type to %s, device = %s\n", data->recommended_part_type, gdu_device_get_device_file (device)); gtk_action_activate (GTK_ACTION (data->part_modify_action)); |
