Volume

class Volume(*args, **kwargs)

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

Mounting a GVolume instance is an asynchronous operation. For more information about asynchronous operations, see AsyncResult and Task. To mount a GVolume, first call mount with (at least) the GVolume instance, optionally a MountOperation object and a AsyncReadyCallback.

Typically, one will only want to pass NULL for the MountOperation 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 AsyncResult instance will be passed to the callback. That callback should then call mount_finish with the GVolume instance and the AsyncResult data to see if the operation was completed successfully. If a Error is present when mount_finish is called, then it will be filled with any error information.

Volume Identifiers

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 command line). 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 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().

Methods

class Volume
can_eject() bool

Checks if a volume can be ejected.

can_mount() bool

Checks if a volume can be mounted.

eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Ejects a volume. This is an asynchronous operation, and is finished by calling eject_finish() with the volume and AsyncResult returned in the callback.

Deprecated since version 2.22: Use eject_with_operation() instead.

Parameters:
  • flags – flags affecting the unmount if required for eject

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data that gets passed to callback

eject_finish(result: AsyncResult) bool

Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

Deprecated since version 2.22: Use eject_with_operation_finish() instead.

Parameters:

result – a AsyncResult

eject_with_operation(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Ejects a volume. This is an asynchronous operation, and is finished by calling eject_with_operation_finish() with the volume and AsyncResult data returned in the callback.

Added in version 2.22.

Parameters:
  • flags – flags affecting the unmount if required for eject

  • mount_operation – a MountOperation or None to avoid user interaction

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data passed to callback

eject_with_operation_finish(result: AsyncResult) bool

Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

Added in version 2.22.

Parameters:

result – a AsyncResult

enumerate_identifiers() list[str]

Gets the kinds of identifiers <``volume`-identifiers>`_ that volume has. Use get_identifier() to obtain the identifiers themselves.

get_activation_root() File | None

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

GMount *mount;
GFile *mount_root
GFile *volume_activation_root;

mount = g_volume_get_mount (volume); // mounted, so never NULL
mount_root = g_mount_get_root (mount);
volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL

then the expression

(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 VolumeMonitor implementations to find the underlying mount to shadow, see is_shadowed() for more details.

Added in version 2.18.

get_drive() Drive | None

Gets the drive for the volume.

get_icon() Icon

Gets the icon for volume.

get_identifier(kind: str) str | None

Gets the identifier of the given kind for volume. See the introduction <``volume`-identifiers>`_ for more information about volume identifiers.

Parameters:

kind – the kind of identifier to return

get_mount() Mount | None

Gets the mount for the volume.

get_name() str

Gets the name of volume.

get_sort_key() str | None

Gets the sort key for volume, if any.

Added in version 2.32.

get_symbolic_icon() Icon

Gets the symbolic icon for volume.

Added in version 2.34.

get_uuid() str | None

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 None if there is no UUID available.

mount(flags: MountMountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Mounts a volume. This is an asynchronous operation, and is finished by calling mount_finish() with the volume and AsyncResult returned in the callback.

Parameters:
  • flags – flags affecting the operation

  • mount_operation – a MountOperation or None to avoid user interaction

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data that gets passed to callback

mount_finish(result: AsyncResult) bool

Finishes mounting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

If the mount operation succeeded, get_mount() on volume is guaranteed to return the mount right after calling this function; there’s no need to listen for the ‘mount-added’ signal on VolumeMonitor.

Parameters:

result – a AsyncResult

should_automount() bool

Returns whether the volume should be automatically mounted.

Signals

class Volume.signals
changed() None

Emitted when the volume has been changed.

removed() None

This signal is emitted when the Volume have been removed. If the recipient is holding references to the object they should release them so the object can be finalized.

Virtual Methods

class Volume
do_can_eject() bool

Checks if a volume can be ejected.

do_can_mount() bool

Checks if a volume can be mounted.

do_changed() None

Changed signal that is emitted when the volume’s state has changed.

do_eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Ejects a volume. This is an asynchronous operation, and is finished by calling eject_finish() with the volume and AsyncResult returned in the callback.

Deprecated since version 2.22: Use eject_with_operation() instead.

Parameters:
  • flags – flags affecting the unmount if required for eject

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data that gets passed to callback

do_eject_finish(result: AsyncResult) bool

Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

Deprecated since version 2.22: Use eject_with_operation_finish() instead.

Parameters:

result – a AsyncResult

do_eject_with_operation(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Ejects a volume. This is an asynchronous operation, and is finished by calling eject_with_operation_finish() with the volume and AsyncResult data returned in the callback.

Added in version 2.22.

Parameters:
  • flags – flags affecting the unmount if required for eject

  • mount_operation – a MountOperation or None to avoid user interaction

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data passed to callback

do_eject_with_operation_finish(result: AsyncResult) bool

Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

Added in version 2.22.

Parameters:

result – a AsyncResult

do_enumerate_identifiers() list[str]

Gets the kinds of identifiers <``volume`-identifiers>`_ that volume has. Use get_identifier() to obtain the identifiers themselves.

do_get_activation_root() File | None

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

GMount *mount;
GFile *mount_root
GFile *volume_activation_root;

mount = g_volume_get_mount (volume); // mounted, so never NULL
mount_root = g_mount_get_root (mount);
volume_activation_root = g_volume_get_activation_root (volume); // assume not NULL

then the expression

(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 VolumeMonitor implementations to find the underlying mount to shadow, see is_shadowed() for more details.

Added in version 2.18.

do_get_drive() Drive | None

Gets the drive for the volume.

do_get_icon() Icon

Gets the icon for volume.

do_get_identifier(kind: str) str | None

Gets the identifier of the given kind for volume. See the introduction <``volume`-identifiers>`_ for more information about volume identifiers.

Parameters:

kind – the kind of identifier to return

do_get_mount() Mount | None

Gets the mount for the volume.

do_get_name() str

Gets the name of volume.

do_get_sort_key() str | None

Gets the sort key for volume, if any.

Added in version 2.32.

do_get_symbolic_icon() Icon

Gets the symbolic icon for volume.

Added in version 2.34.

do_get_uuid() str | None

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 None if there is no UUID available.

do_mount_finish(result: AsyncResult) bool

Finishes mounting a volume. If any errors occurred during the operation, error will be set to contain the errors and False will be returned.

If the mount operation succeeded, get_mount() on volume is guaranteed to return the mount right after calling this function; there’s no need to listen for the ‘mount-added’ signal on VolumeMonitor.

Parameters:

result – a AsyncResult

do_mount_fn(flags: MountMountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Mounts a volume. This is an asynchronous operation, and is finished by calling mount_finish() with the volume and AsyncResult returned in the callback.

Parameters:
  • flags – flags affecting the operation

  • mount_operation – a MountOperation or None to avoid user interaction

  • cancellable – optional Cancellable object, None to ignore

  • callback – a AsyncReadyCallback, or None

  • user_data – user data that gets passed to callback

do_removed() None

The removed signal that is emitted when the Volume have been removed. If the recipient is holding references to the object they should release them so the object can be finalized.

do_should_automount() bool

Returns whether the volume should be automatically mounted.