GduDrive

GduDrive — Drives

Synopsis

                    GduDriveClass;
                    GduDrivePrivate;
enum                GduCreateVolumeFlags;
                    GduDrive;
gboolean            gdu_drive_is_active                 (GduDrive *drive);
gboolean            gdu_drive_is_activatable            (GduDrive *drive);
gboolean            gdu_drive_can_deactivate            (GduDrive *drive);
gboolean            gdu_drive_can_activate              (GduDrive *drive,
                                                         gboolean *out_degraded);
void                gdu_drive_activate                  (GduDrive *drive,
                                                         GduDriveActivateFunc callback,
                                                         gpointer user_data);
void                gdu_drive_deactivate                (GduDrive *drive,
                                                         GduDriveDeactivateFunc callback,
                                                         gpointer user_data);
gboolean            gdu_drive_can_create_volume         (GduDrive *drive,
                                                         gboolean *out_is_uninitialized,
                                                         guint64 *out_largest_contiguous_free_segment,
                                                         guint64 *out_total_free,
                                                         GduPresentable **out_presentable);
void                gdu_drive_create_volume             (GduDrive *drive,
                                                         guint64 size,
                                                         const gchar *name,
                                                         GduCreateVolumeFlags flags,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
GduVolume *         gdu_drive_create_volume_finish      (GduDrive *drive,
                                                         GAsyncResult *res,
                                                         GError **error);
gboolean            gdu_drive_count_mbr_partitions      (GduDrive *drive,
                                                         guint *out_num_primary_partitions,
                                                         gboolean *out_has_extended_partition);
GList *             gdu_drive_get_volumes               (GduDrive *drive);

Object Hierarchy

  GObject
   +----GduDrive
         +----GduLinuxMdDrive

Implemented Interfaces

GduDrive implements GduPresentable.

Description

The GduDrive class represents drives attached to the system. Normally, objects of this class corresponds 1:1 to physical drives (hard disks, optical drives, card readers etc.) attached to the system. However, it can also relate to software abstractions such as a Linux md Software RAID array and similar things.

See the documentation for GduPresentable for the big picture.

Details

GduDriveClass

typedef struct {
        GObjectClass parent_class;

        /* VTable */
        gboolean    (*is_active)             (GduDrive              *drive);
        gboolean    (*is_activatable)        (GduDrive              *drive);
        gboolean    (*can_deactivate)        (GduDrive              *drive);
        gboolean    (*can_activate)          (GduDrive              *drive,
                                              gboolean              *out_degraded);
        void        (*activate)              (GduDrive              *drive,
                                              GduDriveActivateFunc   callback,
                                              gpointer               user_data);
        void        (*deactivate)            (GduDrive              *drive,
                                              GduDriveDeactivateFunc callback,
                                              gpointer               user_data);

        gboolean   (*can_create_volume)     (GduDrive        *drive,
                                             gboolean        *out_is_uninitialized,
                                             guint64         *out_largest_contiguous_free_segment,
                                             guint64         *out_total_free,
                                             GduPresentable **out_presentable);

        void       (*create_volume)         (GduDrive              *drive,
                                             guint64                size,
                                             const gchar           *name,
                                             GduCreateVolumeFlags   flags,
                                             GAsyncReadyCallback    callback,
                                             gpointer               user_data);

        GduVolume *(*create_volume_finish) (GduDrive              *drive,
                                            GAsyncResult          *res,
                                            GError               **error);
} GduDriveClass;


GduDrivePrivate

typedef struct _GduDrivePrivate GduDrivePrivate;


enum GduCreateVolumeFlags

typedef enum {
        GDU_CREATE_VOLUME_FLAGS_NONE = 0x00,
        GDU_CREATE_VOLUME_FLAGS_LINUX_MD = (1<<0),
        GDU_CREATE_VOLUME_FLAGS_LINUX_LVM2 = (1<<1)
} GduCreateVolumeFlags;

Flags used in gdu_drive_create_volume().

GDU_CREATE_VOLUME_FLAGS_NONE

No flags are set.

GDU_CREATE_VOLUME_FLAGS_LINUX_MD

The volume is to be used for Linux MD RAID.

GDU_CREATE_VOLUME_FLAGS_LINUX_LVM2

The volume is to be used for Linux LVM2.

GduDrive

typedef struct _GduDrive GduDrive;


gdu_drive_is_active ()

gboolean            gdu_drive_is_active                 (GduDrive *drive);

drive :

Returns :


gdu_drive_is_activatable ()

gboolean            gdu_drive_is_activatable            (GduDrive *drive);

drive :

Returns :


gdu_drive_can_deactivate ()

gboolean            gdu_drive_can_deactivate            (GduDrive *drive);

drive :

Returns :


gdu_drive_can_activate ()

gboolean            gdu_drive_can_activate              (GduDrive *drive,
                                                         gboolean *out_degraded);

Checks if drive can be activated. If this function returns TRUE, out_degraded will be set to whether the drive will be started in degraded mode (e.g. starting a mirror RAID array with only one component available).

drive :

A GduDrive.

out_degraded :

NULL or return location for whether the drive will be degraded if activated.

Returns :

TRUE if drive can be activated (and out_degraded will be set), FALSE otherwise.

gdu_drive_activate ()

void                gdu_drive_activate                  (GduDrive *drive,
                                                         GduDriveActivateFunc callback,
                                                         gpointer user_data);

drive :

callback :

user_data :


gdu_drive_deactivate ()

void                gdu_drive_deactivate                (GduDrive *drive,
                                                         GduDriveDeactivateFunc callback,
                                                         gpointer user_data);

drive :

callback :

user_data :


gdu_drive_can_create_volume ()

gboolean            gdu_drive_can_create_volume         (GduDrive *drive,
                                                         gboolean *out_is_uninitialized,
                                                         guint64 *out_largest_contiguous_free_segment,
                                                         guint64 *out_total_free,
                                                         GduPresentable **out_presentable);

This method checks if a new volume can be created on drive.

If drive uses removable media and there is no media inserted, FALSE is returned.

If drive appears to be completely uninitialized (such as a hard disk full of zeros), out_is_unitialized is set to TRUE, the size of the media/disk is returned in out_largest_segment and TRUE is returned. Note that this can also happen if drive contains signatures unknown to the operating system so be careful and always prompt the user.

If the disk is partitioned and unallocated space exists but no more partitions can be created (due to e.g. four primary partitions on a MBR partitioned disk), this method returns FALSE but out_largest_segment will be set to a non-zero value.

Additionally, out_presentable will be set to either a GduVolumeHole (if the disk is partitioned and has free space) or the GduDrive (if the disk is uninitialized).

You can use gdu_drive_create_volume() to create a volume.

drive :

A GduDrive.

out_is_uninitialized :

Return location for whether drive is uninitialized or NULL.

out_largest_contiguous_free_segment :

out_total_free :

Return location for total amount of free space on drive or NULL.

out_presentable :

Return location for the presentable that represents free space or NULL. Free with g_object_unref().

Returns :

TRUE if drive has unallocated space, FALSE otherwise.

gdu_drive_create_volume ()

void                gdu_drive_create_volume             (GduDrive *drive,
                                                         guint64 size,
                                                         const gchar *name,
                                                         GduCreateVolumeFlags flags,
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);

High-level method for creating a new volume on drive of size size using name and flags as influential hints.

Depending on the actual type of drive, different things may happen - if drive represents a partitioned drive, then a new partition will be created (and if the partitioning scheme supports partition labels name will be used as the label). If drive is completely uninitialized, it may (or may not) be partitioned.

If drive represents a LVM2 volume group, a logical volume may be created (with name being used as LV name).

This is an asynchronous operation. When the result of the operation is ready, callback will be invoked.

drive :

A GduDrive.

size :

The size of the volume to create.

name :

A name for the volume.

flags :

Flags describing what kind of volume to create

callback :

Function to call when the result is ready.

user_data :

User data to pass to callback.

gdu_drive_create_volume_finish ()

GduVolume *         gdu_drive_create_volume_finish      (GduDrive *drive,
                                                         GAsyncResult *res,
                                                         GError **error);

Finishes an operation started with gdu_drive_create_volume().

drive :

A GduDrive.

res :

A GAsyncResult.

error :

A GError or NULL.

Returns :

A GduVolume for the created volume or NULL if error is set. The returned object must be freed with g_object_unref().

gdu_drive_count_mbr_partitions ()

gboolean            gdu_drive_count_mbr_partitions      (GduDrive *drive,
                                                         guint *out_num_primary_partitions,
                                                         gboolean *out_has_extended_partition);

Counts the number of primary partitions and figures out if there's an extended partition.

drive :

A GduDrive.

out_num_primary_partitions :

Return location for number of primary partitions.

out_has_extended_partition :

Return location for number of extended partitions.

Returns :

TRUE if out_num_logical_partitions and out_has_extended_partition is set, FALSE otherwise.

gdu_drive_get_volumes ()

GList *             gdu_drive_get_volumes               (GduDrive *drive);

Returns a list of all GduVolumes for drive.

drive :

A GduDrive

Returns :

A GList of GduVolume objects. The caller must free the list and each element.