[gnome-disk-utility] Export methods used to identify volumes
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-disk-utility] Export methods used to identify volumes
- Date: Fri, 19 Feb 2010 20:10:48 +0000 (UTC)
commit 537eda47e81c8ad4ce2f2aef49c883779ef593a9
Author: David Zeuthen <davidz redhat com>
Date: Fri Feb 19 12:51:16 2010 -0500
Export methods used to identify volumes
This is essentially already available on GduPresentable but we want
move all callers to this new interface so we can remove it from
GduPresentable some day.
Signed-off-by: David Zeuthen <davidz redhat com>
src/gdu/gdu-volume.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/gdu/gdu-volume.h | 29 +++++++++-
2 files changed, 174 insertions(+), 6 deletions(-)
---
diff --git a/src/gdu/gdu-volume.c b/src/gdu/gdu-volume.c
index 3a643b4..a27e68f 100644
--- a/src/gdu/gdu-volume.c
+++ b/src/gdu/gdu-volume.c
@@ -64,6 +64,10 @@ G_DEFINE_TYPE_WITH_CODE (GduVolume, gdu_volume, G_TYPE_OBJECT,
static void device_job_changed (GduDevice *device, gpointer user_data);
static void device_changed (GduDevice *device, gpointer user_data);
+static gboolean gdu_volume_is_allocated_real (GduVolume *volume);
+static gboolean gdu_volume_is_recognized_real (GduVolume *volume);
+static GduVolumeFlags gdu_volume_get_flags_real (GduVolume *volume);
+
static const struct
{
const char *disc_type;
@@ -129,6 +133,10 @@ gdu_volume_class_init (GduVolumeClass *klass)
obj_class->finalize = gdu_volume_finalize;
+ klass->is_allocated = gdu_volume_is_allocated_real;
+ klass->is_recognized = gdu_volume_is_recognized_real;
+ klass->get_flags = gdu_volume_get_flags_real;
+
g_type_class_add_private (klass, sizeof (GduVolumePrivate));
}
@@ -728,13 +736,13 @@ gdu_volume_get_pool (GduPresentable *presentable)
static gboolean
-gdu_volume_is_allocated (GduPresentable *presentable)
+gdu_volume_presentable_is_allocated (GduPresentable *presentable)
{
return TRUE;
}
static gboolean
-gdu_volume_is_recognized (GduPresentable *presentable)
+gdu_volume_presentable_is_recognized (GduPresentable *presentable)
{
GduVolume *volume = GDU_VOLUME (presentable);
gboolean is_extended_partition;
@@ -767,8 +775,8 @@ gdu_volume_presentable_iface_init (GduPresentableIface *iface)
iface->get_offset = gdu_volume_get_offset;
iface->get_size = gdu_volume_get_size;
iface->get_pool = gdu_volume_get_pool;
- iface->is_allocated = gdu_volume_is_allocated;
- iface->is_recognized = gdu_volume_is_recognized;
+ iface->is_allocated = gdu_volume_presentable_is_allocated;
+ iface->is_recognized = gdu_volume_presentable_is_recognized;
}
void
@@ -796,3 +804,138 @@ _gdu_volume_rewrite_enclosing_presentable (GduVolume *volume)
out:
;
}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+gboolean
+gdu_volume_is_allocated (GduVolume *volume)
+{
+ GduVolumeClass *klass = GDU_VOLUME_GET_CLASS (volume);
+ return klass->is_allocated (volume);
+}
+
+gboolean
+gdu_volume_is_recognized (GduVolume *volume)
+{
+ GduVolumeClass *klass = GDU_VOLUME_GET_CLASS (volume);
+ return klass->is_recognized (volume);
+}
+
+GduVolumeFlags
+gdu_volume_get_flags (GduVolume *volume)
+{
+ GduVolumeClass *klass = GDU_VOLUME_GET_CLASS (volume);
+ return klass->get_flags (volume);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gboolean
+gdu_volume_is_allocated_real (GduVolume *volume)
+{
+ GduDevice *d;
+ gboolean ret;
+
+ ret = FALSE;
+ d = gdu_presentable_get_device (GDU_PRESENTABLE (volume));
+ if (d != NULL) {
+ ret = TRUE;
+ g_object_unref (d);
+ }
+
+ return ret;
+}
+
+static gboolean
+gdu_volume_is_recognized_real (GduVolume *volume)
+{
+ GduDevice *d;
+ gboolean ret;
+
+ ret = FALSE;
+ d = gdu_presentable_get_device (GDU_PRESENTABLE (volume));
+ if (d != NULL) {
+ gboolean is_extended_partition;
+ is_extended_partition = FALSE;
+ if (gdu_device_is_partition (d) && g_strcmp0 (gdu_device_partition_get_scheme (d), "mbr") == 0) {
+ gint type;
+ type = strtol (gdu_device_partition_get_type (d), NULL, 0);
+ if (type == 0x05 || type == 0x0f || type == 0x85) {
+ is_extended_partition = TRUE;
+ }
+ }
+
+ if (is_extended_partition)
+ ret = TRUE;
+ else if (strlen (gdu_device_id_get_usage (volume->priv->device)) > 0)
+ ret = TRUE;
+
+ g_object_unref (d);
+ }
+
+ return ret;
+}
+
+static GduVolumeFlags
+gdu_volume_get_flags_real (GduVolume *volume)
+{
+ GduVolumeFlags ret;
+ GduDevice *d;
+
+ ret = GDU_VOLUME_FLAGS_NONE;
+
+ d = gdu_presentable_get_device (GDU_PRESENTABLE (volume));
+ if (d != NULL) {
+ if (gdu_device_is_partition (d)) {
+ ret |= GDU_VOLUME_FLAGS_PARTITION;
+ }
+
+ if (g_strcmp0 (gdu_device_partition_get_scheme (d), "mbr") == 0) {
+ gint type;
+
+ type = strtol (gdu_device_partition_get_type (volume->priv->device), NULL, 0);
+ if (type == 0x05 || type == 0x0f || type == 0x85) {
+ ret |= GDU_VOLUME_FLAGS_PARTITION_MBR_EXTENDED;
+ }
+
+ if (gdu_device_partition_get_number (d) >= 5)
+ ret |= GDU_VOLUME_FLAGS_PARTITION_MBR_LOGICAL;
+ }
+ g_object_unref (d);
+ }
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+GduDrive *
+gdu_volume_get_drive (GduVolume *volume)
+{
+ GduDrive *ret;
+ GduPresentable *p;
+
+ ret = NULL;
+
+ p = GDU_PRESENTABLE (volume);
+ do {
+ GduPresentable *enclosing;
+
+ enclosing = gdu_presentable_get_enclosing_presentable (p);
+ if (enclosing == NULL)
+ goto out;
+
+ if (GDU_IS_DRIVE (enclosing)) {
+ ret = GDU_DRIVE (enclosing);
+ goto out;
+ }
+
+ g_object_unref (enclosing);
+ p = enclosing;
+
+ } while (TRUE);
+
+ out:
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/gdu/gdu-volume.h b/src/gdu/gdu-volume.h
index 69f18a9..3ac3d58 100644
--- a/src/gdu/gdu-volume.h
+++ b/src/gdu/gdu-volume.h
@@ -30,6 +30,22 @@
G_BEGIN_DECLS
+/**
+ * GduVolumeFlags:
+ * @GDU_VOLUME_FLAGS_NONE: No flags set
+ * @GDU_VOLUME_FLAGS_PARTITION: The volume is a partition.
+ * @GDU_VOLUME_FLAGS_PARTITION_MBR_LOGICAL: The volume is a Logical Partition in the MBR partitioning scheme.
+ * @GDU_VOLUME_FLAGS_PARTITION_MBR_EXTENDED: The volume is an Extended Partition in the MBR partitioning scheme.
+ *
+ * Various flags for describing a volume.
+ */
+typedef enum {
+ GDU_VOLUME_FLAGS_NONE = 0x0000,
+ GDU_VOLUME_FLAGS_PARTITION = (1<<0),
+ GDU_VOLUME_FLAGS_PARTITION_MBR_LOGICAL = (1<<1),
+ GDU_VOLUME_FLAGS_PARTITION_MBR_EXTENDED = (1<<2)
+} GduVolumeFlags;
+
#define GDU_TYPE_VOLUME (gdu_volume_get_type ())
#define GDU_VOLUME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDU_TYPE_VOLUME, GduVolume))
#define GDU_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GDU_VOLUME, GduVolumeClass))
@@ -44,16 +60,25 @@ struct _GduVolume
{
GObject parent;
- /* private */
+ /*< private >*/
GduVolumePrivate *priv;
};
struct _GduVolumeClass
{
GObjectClass parent_class;
+
+ gboolean (*is_allocated) (GduVolume *volume);
+ gboolean (*is_recognized) (GduVolume *volume);
+ GduVolumeFlags (*get_flags) (GduVolume *volume);
};
-GType gdu_volume_get_type (void);
+GType gdu_volume_get_type (void);
+gboolean gdu_volume_is_allocated (GduVolume *volume);
+gboolean gdu_volume_is_recognized (GduVolume *volume);
+GduVolumeFlags gdu_volume_get_flags (GduVolume *volume);
+GduDrive *gdu_volume_get_drive (GduVolume *volume);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]