Volume#
- class Volume(*args, **kwargs)#
The GVolume interface represents user-visible objects that can be
mounted. For example, a file system partition on a USB flash drive, or an
optical disc inserted into a disc drive.
If a GVolume is currently mounted, the corresponding Mount can
be retrieved using get_mount.
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.
Note, when porting from GnomeVFS,
GVolume is the moral equivalent of GnomeVFSDrive.
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
-
- async eject(self, flags: MountUnmountFlags) bool#
This is the awaitable version of
eject().Deprecated since version 2.22: Use
eject_with_operation()instead.- Parameters:
flags – flags affecting the unmount if required for eject
- eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Ejects a volume. This is an asynchronous operation, and is finished by calling
eject_finish()with thevolumeandAsyncResultreturned in thecallback.Deprecated since version 2.22: Use
eject_with_operation()instead.- Parameters:
flags – flags affecting the unmount if required for eject
cancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_data – user data that gets passed to
callback
- eject_finish(result: AsyncResult) bool#
Finishes ejecting a volume. If any errors occurred during the operation,
errorwill be set to contain the errors andFalsewill be returned.Deprecated since version 2.22: Use
eject_with_operation_finish()instead.- Parameters:
result – a
AsyncResult
- async eject_with_operation(self, flags: MountUnmountFlags, mount_operation: MountOperation | None = None) bool#
This is the awaitable version of
eject_with_operation().Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for eject
mount_operation – a
MountOperationorNoneto avoid user interaction
- eject_with_operation(flags: MountUnmountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Ejects a volume. This is an asynchronous operation, and is finished by calling
eject_with_operation_finish()with thevolumeandAsyncResultdata returned in thecallback.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for eject
mount_operation – a
MountOperationorNoneto avoid user interactioncancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_data – user data passed to
callback
- eject_with_operation_finish(result: AsyncResult) bool#
Finishes ejecting a volume. If any errors occurred during the operation,
errorwill be set to contain the errors andFalsewill be returned.Added in version 2.22.
- Parameters:
result – a
AsyncResult
- enumerate_identifiers() list[str]#
Gets the kinds of identifiers that
volumehas. Useget_identifier()to obtain the identifiers themselves.
- get_activation_root() File | None#
Gets the activation root for a
Volumeif it is known ahead of mount time. ReturnsNoneotherwise. If notNoneand ifvolumeis mounted, then the result ofget_root()on theMountobject obtained fromget_mount()will always either be equal or a prefix of what this function returns. In other words, in codeGMount *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
VolumeMonitorimplementations to find the underlying mount to shadow, seeis_shadowed()for more details.Added in version 2.18.
- get_identifier(kind: str) str | None#
Gets the identifier of the given kind for
volume. See the introduction for more information about volume identifiers.- Parameters:
kind – the kind of identifier to return
- 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. ReturnsNoneif there is no UUID available.
- async mount(self, flags: MountMountFlags, mount_operation: MountOperation | None = None) bool#
This is the awaitable version of
mount().- Parameters:
flags – flags affecting the operation
mount_operation – a
MountOperationorNoneto avoid user interaction
- mount(flags: MountMountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Mounts a volume. This is an asynchronous operation, and is finished by calling
mount_finish()with thevolumeandAsyncResultreturned in thecallback.- Parameters:
flags – flags affecting the operation
mount_operation – a
MountOperationorNoneto avoid user interactioncancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_data – user data that gets passed to
callback
- mount_finish(result: AsyncResult) bool#
Finishes mounting a volume. If any errors occurred during the operation,
errorwill be set to contain the errors andFalsewill be returned.If the mount operation succeeded,
get_mount()onvolumeis guaranteed to return the mount right after calling this function; there’s no need to listen for the ‘mount-added’ signal onVolumeMonitor.- Parameters:
result – a
AsyncResult
Signals#
Virtual Methods#
- class Volume
-
- do_eject(flags: MountUnmountFlags, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Ejects a volume. This is an asynchronous operation, and is finished by calling
eject_finish()with thevolumeandAsyncResultreturned in thecallback.Deprecated since version 2.22: Use
eject_with_operation()instead.- Parameters:
flags – flags affecting the unmount if required for eject
cancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_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,
errorwill be set to contain the errors andFalsewill 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[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Ejects a volume. This is an asynchronous operation, and is finished by calling
eject_with_operation_finish()with thevolumeandAsyncResultdata returned in thecallback.Added in version 2.22.
- Parameters:
flags – flags affecting the unmount if required for eject
mount_operation – a
MountOperationorNoneto avoid user interactioncancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_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,
errorwill be set to contain the errors andFalsewill be returned.Added in version 2.22.
- Parameters:
result – a
AsyncResult
- do_enumerate_identifiers() list[str]#
Gets the kinds of identifiers that
volumehas. Useget_identifier()to obtain the identifiers themselves.
- do_get_activation_root() File | None#
Gets the activation root for a
Volumeif it is known ahead of mount time. ReturnsNoneotherwise. If notNoneand ifvolumeis mounted, then the result ofget_root()on theMountobject obtained fromget_mount()will always either be equal or a prefix of what this function returns. In other words, in codeGMount *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
VolumeMonitorimplementations to find the underlying mount to shadow, seeis_shadowed()for more details.Added in version 2.18.
- do_get_identifier(kind: str) str | None#
Gets the identifier of the given kind for
volume. See the introduction for more information about volume identifiers.- Parameters:
kind – the kind of identifier to return
- 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. ReturnsNoneif there is no UUID available.
- do_mount_finish(result: AsyncResult) bool#
Finishes mounting a volume. If any errors occurred during the operation,
errorwill be set to contain the errors andFalsewill be returned.If the mount operation succeeded,
get_mount()onvolumeis guaranteed to return the mount right after calling this function; there’s no need to listen for the ‘mount-added’ signal onVolumeMonitor.- Parameters:
result – a
AsyncResult
- do_mount_fn(flags: MountMountFlags, mount_operation: MountOperation | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
The type of the None singleton.
- Parameters:
flags – flags affecting the operation
mount_operation – a
MountOperationorNoneto avoid user interactioncancellable – optional
Cancellableobject,Noneto ignorecallback – a
AsyncReadyCallback, orNoneuser_data – user data that gets passed to
callback