Module: Gio::Volume

Defined in:
(unknown)

Overview

The #GVolume interface represents user-visible objects that can be mounted. Note, when porting from GnomeVFS, #GVolume is the moral equivalent of Gnome::VFSDrive.

Mounting a #GVolume instance is an asynchronous operation. For more information about asynchronous operations, see GAsync::Result and #GTask. To mount a #GVolume, first call g_volume_mount() with (at least) the #GVolume instance, optionally a GMount::Operation object and a GAsync::ReadyCallback.

Typically, one will only want to pass nil for the GMount::Operation if automounting all volumes when a desktop session starts since it’s not desirable to put up a lot of dialogs asking for credentials.

The callback will be fired when the operation has resolved (either with success or failure), and a GAsync::Result instance will be passed to the callback. That callback should then call g_volume_mount_finish() with the #GVolume instance and the GAsync::Result data to see if the operation was completed successfully. If an error is present when g_volume_mount_finish() is called, then it will be filled with any error information.

## Volume Identifiers # #volume-identifier

It is sometimes necessary to directly access the underlying operating system object behind a volume (e.g. for passing a volume to an application via the commandline). For this purpose, GIO allows to obtain an ‘identifier’ for the volume. There can be different kinds of identifiers, such as Hal UDIs, filesystem labels, traditional Unix devices (e.g. ‘/dev/sda2`), UUIDs. GIO uses predefined strings as names for the different kinds of identifiers: #G_VOLUME_IDENTIFIER_KIND_UUID, #G_VOLUME_IDENTIFIER_KIND_LABEL, etc. Use g_volume_get_identifier() to obtain an identifier for a volume.

Note that #G_VOLUME_IDENTIFIER_KIND_HAL_UDI will only be available when the gvfs hal volume monitor is in use. Other volume monitors will generally be able to provide the #G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE identifier, which can be used to obtain a hal device by means of libhal_manager_find_device_string_match().

Instance Method Summary collapse

Instance Method Details

#activation_rootGio::File

Gets the activation root for a #GVolume if it is known ahead of mount time. Returns nil otherwise. If not nil and if volume is mounted, then the result of g_mount_get_root() on the #GMount object obtained from g_volume_get_mount() will always either be equal or a prefix of what this function returns. In other words, in code

(g_file_has_prefix (volume_activation_root, mount_root) ||
 g_file_equal (volume_activation_root, mount_root))

will always be true.

Activation roots are typically used in GVolume::Monitor implementations to find the underlying mount to shadow, see g_mount_is_shadowed() for more details.

Returns:

  • (Gio::File)

    the activation root of volume or nil. Use g_object_unref() to free.

#can_eject(volume) ⇒ TrueClass

Returns true if the volume can be ejected. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the volume can be ejected. false otherwise

#can_mount(volume) ⇒ TrueClass

Returns true if the volume can be mounted. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the volume can be mounted. false otherwise

#changed(volume) ⇒ nil

Parameters:

Returns:

  • (nil)

#driveGio::Drive

Gets the drive for the volume.

Returns:

  • (Gio::Drive)

    a #GDrive or nil if volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.

#eject(volume, flags, cancellable, callback, user_data) ⇒ nil

Parameters:

  • volume (Gio::Volume)

    a #GVolume

  • flags (Gio::MountUnmountFlags)

    flags affecting the unmount if required for eject

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback, or nil

  • user_data (GObject)

    user data that gets passed to callback

Returns:

  • (nil)

#eject_finish(volume, result) ⇒ TrueClass

Returns true, false if operation failed.

Parameters:

Returns:

  • (TrueClass)

    true, false if operation failed

#eject_with_operation(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • volume (Gio::Volume)

    a #GVolume

  • flags (Gio::MountUnmountFlags)

    flags affecting the unmount if required for eject

  • mount_operation (Gio::MountOperation)

    a GMount::Operation or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback, or nil

  • user_data (GObject)

    user data passed to callback

Returns:

  • (nil)

#eject_with_operation_finish(volume, result) ⇒ TrueClass

Returns true if the volume was successfully ejected. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the volume was successfully ejected. false otherwise

#enumerate_identifiers(volume) ⇒ Array<String>

Returns an array of strings containing kinds of identifiers. Use g_strfreev() to free.

Parameters:

Returns:

  • (Array<String>)

    an array of strings containing kinds of identifiers. Use g_strfreev() to free.

#get_activation_root(volume) ⇒ Gio::File

Returns the activation root of volume or nil. Use g_object_unref() to free.

Parameters:

Returns:

  • (Gio::File)

    the activation root of volume or nil. Use g_object_unref() to free.

#get_drive(volume) ⇒ Gio::Drive

Returns a #GDrive or nil if volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.

Parameters:

Returns:

  • (Gio::Drive)

    a #GDrive or nil if volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.

#get_icon(volume) ⇒ Gio::Icon

Returns a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

Parameters:

Returns:

  • (Gio::Icon)

    a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

#get_identifier(volume, kind) ⇒ String

Returns a newly allocated string containing the requested identifier, or nil if the #GVolume doesn’t have this kind of identifier.

Parameters:

  • volume (Gio::Volume)

    a #GVolume

  • kind (String)

    the kind of identifier to return

Returns:

  • (String)

    a newly allocated string containing the requested identifier, or nil if the #GVolume doesn’t have this kind of identifier

#get_mount(volume) ⇒ Gio::Mount

Returns a #GMount or nil if volume isn’t mounted. The returned object should be unreffed with g_object_unref() when no longer needed.

Parameters:

Returns:

  • (Gio::Mount)

    a #GMount or nil if volume isn’t mounted. The returned object should be unreffed with g_object_unref() when no longer needed.

#get_name(volume) ⇒ String

Returns the name for the given volume. The returned string should be freed with g_free() when no longer needed.

Parameters:

Returns:

  • (String)

    the name for the given volume. The returned string should be freed with g_free() when no longer needed.

#get_sort_key(volume) ⇒ String

Returns Sorting key for volume or nil if no such key is available.

Parameters:

Returns:

  • (String)

    Sorting key for volume or nil if no such key is available

#get_symbolic_icon(volume) ⇒ Gio::Icon

Returns a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

Parameters:

Returns:

  • (Gio::Icon)

    a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

#get_uuid(volume) ⇒ String

Returns the UUID for volume or nil if no UUID can be computed. The returned string should be freed with g_free() when no longer needed.

Parameters:

Returns:

  • (String)

    the UUID for volume or nil if no UUID can be computed. The returned string should be freed with g_free() when no longer needed.

#iconGio::Icon

Gets the icon for volume.

Returns:

  • (Gio::Icon)

    a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

#mount(flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the volume and GAsync::Result returned in the callback.

Parameters:

  • flags (Gio::MountMountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback, or nil

  • user_data (GObject)

    user data that gets passed to callback

Returns:

  • (nil)

#mount_finish(volume, result) ⇒ TrueClass

Returns true, false if operation failed.

Parameters:

Returns:

  • (TrueClass)

    true, false if operation failed

#mount_fn(volume, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • volume (Gio::Volume)

    a #GVolume

  • flags (Gio::MountMountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback, or nil

  • user_data (GObject)

    user data that gets passed to callback

Returns:

  • (nil)

#nameString

Gets the name of volume.

Returns:

  • (String)

    the name for the given volume. The returned string should be freed with g_free() when no longer needed.

#removed(volume) ⇒ nil

Parameters:

Returns:

  • (nil)

#should_automount(volume) ⇒ TrueClass

Returns true if the volume should be automatically mounted.

Parameters:

Returns:

  • (TrueClass)

    true if the volume should be automatically mounted

#sort_keyString

Gets the sort key for volume, if any.

Returns:

  • (String)

    Sorting key for volume or nil if no such key is available

#symbolic_iconGio::Icon

Gets the symbolic icon for volume.

Returns:

  • (Gio::Icon)

    a #GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.

#uuidString

Gets the UUID for the volume. The reference is typically based on the file system UUID for the volume in question and should be considered an opaque string. Returns nil if there is no UUID available.

Returns:

  • (String)

    the UUID for volume or nil if no UUID can be computed. The returned string should be freed with g_free() when no longer needed.