[gnome-disk-utility] rework partition table handling



commit 086e51cd6696828d5f4194aaee27bd78b373f54c
Author: David Zeuthen <davidz redhat com>
Date:   Tue Mar 31 15:33:22 2009 -0400

    rework partition table handling
---
 src/gdu/gdu-device.c                     |   38 --------------------
 src/gdu/gdu-device.h                     |    3 --
 src/gdu/gdu-pool.c                       |   56 +++++++++++++++++++-----------
 src/palimpsest/gdu-section-unallocated.c |    8 ++---
 4 files changed, 39 insertions(+), 66 deletions(-)

diff --git a/src/gdu/gdu-device.c b/src/gdu/gdu-device.c
index 8205151..bc79c69 100644
--- a/src/gdu/gdu-device.c
+++ b/src/gdu/gdu-device.c
@@ -101,9 +101,6 @@ typedef struct
 
         char    *partition_table_scheme;
         int      partition_table_count;
-        int      partition_table_max_number;
-        GArray  *partition_table_offsets;
-        GArray  *partition_table_sizes;
 
         char    *luks_holder;
 
@@ -286,19 +283,6 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
                 props->partition_table_scheme = g_strdup (g_value_get_string (value));
         else if (strcmp (key, "partition-table-count") == 0)
                 props->partition_table_count = g_value_get_int (value);
-        else if (strcmp (key, "partition-table-max-number") == 0)
-                props->partition_table_max_number = g_value_get_int (value);
-        else if (strcmp (key, "partition-table-offsets") == 0) {
-                GValue dest_value = {0,};
-                g_value_init (&dest_value, dbus_g_type_get_collection ("GArray", G_TYPE_UINT64));
-                g_value_copy (value, &dest_value);
-                props->partition_table_offsets = g_value_get_boxed (&dest_value);
-        } else if (strcmp (key, "partition-table-sizes") == 0) {
-                GValue dest_value = {0,};
-                g_value_init (&dest_value, dbus_g_type_get_collection ("GArray", G_TYPE_UINT64));
-                g_value_copy (value, &dest_value);
-                props->partition_table_sizes = g_value_get_boxed (&dest_value);
-        }
 
         else if (strcmp (key, "luks-holder") == 0)
                 props->luks_holder = g_strdup (g_value_get_boxed (value));
@@ -465,10 +449,6 @@ device_properties_free (DeviceProperties *props)
         g_free (props->partition_uuid);
         g_strfreev (props->partition_flags);
         g_free (props->partition_table_scheme);
-        if (props->partition_table_offsets != NULL)
-                g_array_free (props->partition_table_offsets, TRUE);
-        if (props->partition_table_sizes != NULL)
-                g_array_free (props->partition_table_sizes, TRUE);
         g_free (props->luks_holder);
         g_free (props->luks_cleartext_slave);
         g_free (props->drive_model);
@@ -1006,24 +986,6 @@ gdu_device_partition_table_get_count (GduDevice *device)
         return device->priv->props->partition_table_count;
 }
 
-int
-gdu_device_partition_table_get_max_number (GduDevice *device)
-{
-        return device->priv->props->partition_table_max_number;
-}
-
-GArray *
-gdu_device_partition_table_get_offsets (GduDevice *device)
-{
-        return device->priv->props->partition_table_offsets;
-}
-
-GArray *
-gdu_device_partition_table_get_sizes (GduDevice *device)
-{
-        return device->priv->props->partition_table_sizes;
-}
-
 const char *
 gdu_device_luks_get_holder (GduDevice *device)
 {
diff --git a/src/gdu/gdu-device.h b/src/gdu/gdu-device.h
index c3e03ce..33a42c9 100644
--- a/src/gdu/gdu-device.h
+++ b/src/gdu/gdu-device.h
@@ -120,9 +120,6 @@ guint64 gdu_device_partition_get_size (GduDevice *device);
 
 const char *gdu_device_partition_table_get_scheme (GduDevice *device);
 int         gdu_device_partition_table_get_count (GduDevice *device);
-int         gdu_device_partition_table_get_max_number (GduDevice *device);
-GArray     *gdu_device_partition_table_get_offsets (GduDevice *device);
-GArray     *gdu_device_partition_table_get_sizes (GduDevice *device);
 
 const char *gdu_device_luks_get_holder (GduDevice *device);
 
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index c1cfd2b..2749e86 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -378,6 +378,7 @@ part_entry_compare (PartEntry *pa, PartEntry *pb, gpointer user_data)
 
 static GList *
 get_holes (GduPool        *pool,
+           GList          *devices,
            GduDrive       *drive,
            GduDevice      *drive_device,
            GduPresentable *enclosed_in,
@@ -388,16 +389,15 @@ get_holes (GduPool        *pool,
         GList *ret;
         gint n;
         gint num_entries;
-        gint max_number;
-        guint64 *offsets;
-        guint64 *sizes;
         PartEntry *entries;
         guint64 cursor;
         guint64 gap_size;
         guint64 gap_position;
         const char *scheme;
+        GList *l;
 
         ret = NULL;
+        entries = NULL;
 
         /* no point if adding holes if there's no media */
         if (!gdu_device_is_media_available (drive_device))
@@ -414,36 +414,49 @@ get_holes (GduPool        *pool,
                  start + size,
                  ignore_logical);*/
 
-        offsets = (guint64*) ((gdu_device_partition_table_get_offsets (drive_device))->data);
-        sizes = (guint64*) ((gdu_device_partition_table_get_sizes (drive_device))->data);
-        max_number = gdu_device_partition_table_get_max_number (drive_device);
         scheme = gdu_device_partition_table_get_scheme (drive_device);
 
-        entries = g_new0 (PartEntry, max_number);
-        for (n = 0, num_entries = 0; n < max_number; n++) {
-                /* ignore unused partition table entries */
-                if (offsets[n] == 0)
+        /* find the offsets and sizes of existing partitions of the partition table */
+        GArray *entries_array;
+        entries_array = g_array_new (FALSE, FALSE, sizeof (PartEntry));
+        num_entries = 0;
+        for (l = devices; l != NULL; l = l->next) {
+                GduDevice *partition_device = GDU_DEVICE (l->data);
+                guint64 partition_offset;
+                guint64 partition_size;
+                guint partition_number;
+
+                if (!gdu_device_is_partition (partition_device))
                         continue;
+                if (g_strcmp0 (gdu_device_get_object_path (drive_device),
+                               gdu_device_partition_get_slave (partition_device)) != 0)
+                        continue;
+
+                partition_offset = gdu_device_partition_get_offset (partition_device);
+                partition_size = gdu_device_partition_get_size (partition_device);
+                partition_number = gdu_device_partition_get_number (partition_device);
 
                 /* only consider partitions in the given space */
-                if (offsets[n] <= start)
+                if (partition_offset < start)
                         continue;
-                if (offsets[n] >= start + size)
+                if (partition_offset >= start + size)
                         continue;
 
                 /* ignore logical partitions if requested */
                 if (ignore_logical) {
-                        if (strcmp (scheme, "mbr") == 0 && n >= 4)
+                        if (strcmp (scheme, "mbr") == 0 && partition_number >= 4)
                                 continue;
                 }
 
-                entries[num_entries].number = n + 1;
-                entries[num_entries].offset = offsets[n];
-                entries[num_entries].size = sizes[n];
+                g_array_set_size (entries_array, num_entries + 1);
+
+                g_array_index (entries_array, PartEntry, num_entries).number = partition_number;
+                g_array_index (entries_array, PartEntry, num_entries).offset = partition_offset;
+                g_array_index (entries_array, PartEntry, num_entries).size = partition_size;
+
                 num_entries++;
-                //g_print ("%d: offset=%lld size=%lld\n", entries[n].number, entries[n].offset, entries[n].size);
         }
-        entries = g_realloc (entries, num_entries * sizeof (PartEntry));
+        entries = (PartEntry *) g_array_free (entries_array, FALSE);
 
         g_qsort_with_data (entries, num_entries, sizeof (PartEntry), (GCompareDataFunc) part_entry_compare, NULL);
 
@@ -474,13 +487,14 @@ get_holes (GduPool        *pool,
 
         }
 
-        g_free (entries);
 out:
+        g_free (entries);
         return ret;
 }
 
 static GList *
 get_holes_for_drive (GduPool   *pool,
+                     GList     *devices,
                      GduDrive  *drive,
                      GduVolume *extended_partition)
 {
@@ -497,6 +511,7 @@ get_holes_for_drive (GduPool   *pool,
 
         /* first add holes between primary partitions */
         ret = get_holes (pool,
+                         devices,
                          drive,
                          drive_device,
                          GDU_PRESENTABLE (drive),
@@ -517,6 +532,7 @@ get_holes_for_drive (GduPool   *pool,
                 }
 
                 holes_in_extended_partition = get_holes (pool,
+                                                         devices,
                                                          drive,
                                                          drive_device,
                                                          GDU_PRESENTABLE (extended_partition),
@@ -742,7 +758,7 @@ recompute_presentables (GduPool *pool)
                 drive = GDU_DRIVE (l->data);
                 extended_partition = g_hash_table_lookup (hash_map_from_drive_to_extended_partition, drive);
 
-                holes = get_holes_for_drive (pool, drive, extended_partition);
+                holes = get_holes_for_drive (pool, devices, drive, extended_partition);
 
                 new_presentables = g_list_concat (new_presentables, holes);
         }
diff --git a/src/palimpsest/gdu-section-unallocated.c b/src/palimpsest/gdu-section-unallocated.c
index acbce5f..830e66d 100644
--- a/src/palimpsest/gdu-section-unallocated.c
+++ b/src/palimpsest/gdu-section-unallocated.c
@@ -215,11 +215,9 @@ create_partition_callback (GtkAction *action, gpointer user_data)
                 fslabel = g_strdup ("");
         } else {
                 type = gdu_util_get_default_part_type_for_scheme_and_fstype (scheme, fstype, size);
-                if (type == NULL) {
-                        g_warning ("Cannot determine default part type for scheme '%s' and fstype '%s'",
-                                   scheme, fstype);
-                        goto out;
-                }
+                /* it's not a bug if type is NULL here.. it may happen if Palimpsest does not
+                 * know the scheme
+                 */
         }
 
         /* set partition label to the file system label (TODO: handle max len) */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]