Skip to content

Gio.Mount

interface

The GMount interface represents a user-visible mount, such as a mounted file system.

GMount is a ‘mounted’ filesystem that you can access. Mounted is in quotes because it’s not the same as a UNIX mount, it might be a GVFS mount, but you can still access the files on it if you use GIO.

A GMount might be associated with a Volume (such as a USB flash drive) which hosts it.

Unmounting a GMount instance is an asynchronous operation. For more information about asynchronous operations, see AsyncResult and Task. To unmount a GMount instance, first call Mount.unmount_with_operation with (at least) the GMount instance and a AsyncReadyCallback. The callback will be fired when the operation has resolved (either with success or failure), and a AsyncResult structure will be passed to the callback. That callback should then call Mount.unmount_with_operation_finish with the GMount and the AsyncResult data to see if the operation was completed successfully. If an error is present when Mount.unmount_with_operation_finish is called, then it will be filled with any error information.

Note, when porting from GnomeVFS, GMount is the moral equivalent of GnomeVFSVolume.

Methods

can_eject

def can_eject(self) -> bool

Checks if mount can be ejected.

can_unmount

def can_unmount(self) -> bool

Checks if mount can be unmounted.

eject

def eject(self, flags: MountUnmountFlags | int, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

:::warning Deprecated since 2.22 This API is deprecated. :::

Ejects a mount. This is an asynchronous operation, and is finished by calling Mount.eject_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • flags — flags affecting the unmount if required for eject
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback, or None.

eject_finish

def eject_finish(self, result: AsyncResult) -> bool

:::warning Deprecated since 2.22 This API is deprecated. :::

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

Parameters:

eject_with_operation

def eject_with_operation(self, flags: MountUnmountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

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

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 GAsyncReadyCallback, or None.

eject_with_operation_finish

def eject_with_operation_finish(self, result: AsyncResult) -> bool

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

Parameters:

get_default_location

def get_default_location(self) -> File

Gets the default location of mount. The default location of the given mount is a path that reflects the main entry point for the user (e.g. the home directory, or the root of the volume).

get_drive

def get_drive(self) -> Drive | None

Gets the drive for the mount.

This is a convenience method for getting the Volume and then using that object to get the Drive.

get_icon

def get_icon(self) -> Icon

Gets the icon for mount.

get_name

def get_name(self) -> str

Gets the name of mount.

get_root

def get_root(self) -> File

Gets the root directory on mount.

get_sort_key

def get_sort_key(self) -> str | None

Gets the sort key for mount, if any.

get_symbolic_icon

def get_symbolic_icon(self) -> Icon

Gets the symbolic icon for mount.

get_uuid

def get_uuid(self) -> str | None

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

get_volume

def get_volume(self) -> Volume | None

Gets the volume for the mount.

guess_content_type

def guess_content_type(self, force_rescan: bool, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Tries to guess the type of content stored on mount. Returns one or more textual identifiers of well-known content types (typically prefixed with "x-content/"), e.g. x-content/image-dcf for camera memory cards. See the shared-mime-info specification for more on x-content types.

This is an asynchronous operation (see Mount.guess_content_type_sync for the synchronous version), and is finished by calling Mount.guess_content_type_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • force_rescan — Whether to force a rescan of the content. Otherwise a cached result will be used if available
  • cancellable — optional Cancellable object, None to ignore
  • callback — a GAsyncReadyCallback

guess_content_type_finish

def guess_content_type_finish(self, result: AsyncResult) -> list[str]

Finishes guessing content types of mount. If any errors occurred during the operation, error will be set to contain the errors and False will be returned. In particular, you may get an IOErrorEnum.NOT_SUPPORTED if the mount does not support content guessing.

Parameters:

guess_content_type_sync

def guess_content_type_sync(self, force_rescan: bool, cancellable: Cancellable | None = ...) -> list[str]

Tries to guess the type of content stored on mount. Returns one or more textual identifiers of well-known content types (typically prefixed with "x-content/"), e.g. x-content/image-dcf for camera memory cards. See the shared-mime-info specification for more on x-content types.

This is a synchronous operation and as such may block doing IO; see Mount.guess_content_type for the asynchronous version.

Parameters:

  • force_rescan — Whether to force a rescan of the content. Otherwise a cached result will be used if available
  • cancellable — optional Cancellable object, None to ignore

is_shadowed

def is_shadowed(self) -> bool

Determines if mount is shadowed. Applications or libraries should avoid displaying mount in the user interface if it is shadowed.

A mount is said to be shadowed if there exists one or more user visible objects (currently Mount objects) with a root that is inside the root of mount.

One application of shadow mounts is when exposing a single file system that is used to address several logical volumes. In this situation, a VolumeMonitor implementation would create two Volume objects (for example, one for the camera functionality of the device and one for a SD card reader on the device) with activation URIs gphoto2://[usb:001,002]/store1/ and gphoto2://[usb:001,002]/store2/. When the underlying mount (with root gphoto2://[usb:001,002]/) is mounted, said VolumeMonitor implementation would create two Mount objects (each with their root matching the corresponding volume activation root) that would shadow the original mount.

The proxy monitor in GVfs 2.26 and later, automatically creates and manage shadow mounts (and shadows the underlying mount) if the activation root on a Volume is set.

remount

def remount(self, flags: MountMountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Remounts a mount. This is an asynchronous operation, and is finished by calling Mount.remount_finish with the mount and GAsyncResults data returned in the callback.

Remounting is useful when some setting affecting the operation of the volume has been changed, as these may need a remount to take affect. While this is semantically equivalent with unmounting and then remounting not all backends might need to actually be unmounted.

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 GAsyncReadyCallback, or None.

remount_finish

def remount_finish(self, result: AsyncResult) -> bool

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

Parameters:

shadow

def shadow(self) -> None

Increments the shadow count on mount. Usually used by VolumeMonitor implementations when creating a shadow mount for mount, see Mount.is_shadowed for more information. The caller will need to emit the Mount::changed signal on mount manually.

unmount

def unmount(self, flags: MountUnmountFlags | int, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

:::warning Deprecated since 2.22 This API is deprecated. :::

Unmounts a mount. This is an asynchronous operation, and is finished by calling Mount.unmount_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • flags — flags affecting the operation
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback, or None.

unmount_finish

def unmount_finish(self, result: AsyncResult) -> bool

:::warning Deprecated since 2.22 This API is deprecated. :::

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

Parameters:

unmount_with_operation

def unmount_with_operation(self, flags: MountUnmountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Unmounts a mount. This is an asynchronous operation, and is finished by calling Mount.unmount_with_operation_finish with the mount and AsyncResult data 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 GAsyncReadyCallback, or None.

unmount_with_operation_finish

def unmount_with_operation_finish(self, result: AsyncResult) -> bool

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

Parameters:

unshadow

def unshadow(self) -> None

Decrements the shadow count on mount. Usually used by VolumeMonitor implementations when destroying a shadow mount for mount, see Mount.is_shadowed for more information. The caller will need to emit the Mount::changed signal on mount manually.

Virtual methods

do_can_eject

def do_can_eject(self) -> bool

Checks if mount can be ejected.

do_can_unmount

def do_can_unmount(self) -> bool

Checks if mount can be unmounted.

do_changed

def do_changed(self) -> None

Changed signal that is emitted when the mount's state has changed.

do_eject

def do_eject(self, flags: MountUnmountFlags | int, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

:::warning Deprecated since 2.22 This API is deprecated. :::

Ejects a mount. This is an asynchronous operation, and is finished by calling Mount.eject_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • flags — flags affecting the unmount if required for eject
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback, or None.

do_eject_finish

def do_eject_finish(self, result: AsyncResult) -> bool

:::warning Deprecated since 2.22 This API is deprecated. :::

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

Parameters:

do_eject_with_operation

def do_eject_with_operation(self, flags: MountUnmountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

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

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 GAsyncReadyCallback, or None.

do_eject_with_operation_finish

def do_eject_with_operation_finish(self, result: AsyncResult) -> bool

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

Parameters:

do_get_default_location

def do_get_default_location(self) -> File

Gets the default location of mount. The default location of the given mount is a path that reflects the main entry point for the user (e.g. the home directory, or the root of the volume).

do_get_drive

def do_get_drive(self) -> Drive | None

Gets the drive for the mount.

This is a convenience method for getting the Volume and then using that object to get the Drive.

do_get_icon

def do_get_icon(self) -> Icon

Gets the icon for mount.

do_get_name

def do_get_name(self) -> str

Gets the name of mount.

do_get_root

def do_get_root(self) -> File

Gets the root directory on mount.

do_get_sort_key

def do_get_sort_key(self) -> str | None

Gets the sort key for mount, if any.

do_get_symbolic_icon

def do_get_symbolic_icon(self) -> Icon

Gets the symbolic icon for mount.

do_get_uuid

def do_get_uuid(self) -> str | None

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

do_get_volume

def do_get_volume(self) -> Volume | None

Gets the volume for the mount.

do_guess_content_type

def do_guess_content_type(self, force_rescan: bool, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Tries to guess the type of content stored on mount. Returns one or more textual identifiers of well-known content types (typically prefixed with "x-content/"), e.g. x-content/image-dcf for camera memory cards. See the shared-mime-info specification for more on x-content types.

This is an asynchronous operation (see Mount.guess_content_type_sync for the synchronous version), and is finished by calling Mount.guess_content_type_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • force_rescan — Whether to force a rescan of the content. Otherwise a cached result will be used if available
  • cancellable — optional Cancellable object, None to ignore
  • callback — a GAsyncReadyCallback

do_guess_content_type_finish

def do_guess_content_type_finish(self, result: AsyncResult) -> list[str]

Finishes guessing content types of mount. If any errors occurred during the operation, error will be set to contain the errors and False will be returned. In particular, you may get an IOErrorEnum.NOT_SUPPORTED if the mount does not support content guessing.

Parameters:

do_guess_content_type_sync

def do_guess_content_type_sync(self, force_rescan: bool, cancellable: Cancellable | None = ...) -> list[str]

Tries to guess the type of content stored on mount. Returns one or more textual identifiers of well-known content types (typically prefixed with "x-content/"), e.g. x-content/image-dcf for camera memory cards. See the shared-mime-info specification for more on x-content types.

This is a synchronous operation and as such may block doing IO; see Mount.guess_content_type for the asynchronous version.

Parameters:

  • force_rescan — Whether to force a rescan of the content. Otherwise a cached result will be used if available
  • cancellable — optional Cancellable object, None to ignore

do_pre_unmount

def do_pre_unmount(self) -> None

The ::pre-unmount signal that is emitted when the Mount will soon be emitted. If the recipient is somehow holding the mount open by keeping an open file on it it should close the file.

do_remount

def do_remount(self, flags: MountMountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Remounts a mount. This is an asynchronous operation, and is finished by calling Mount.remount_finish with the mount and GAsyncResults data returned in the callback.

Remounting is useful when some setting affecting the operation of the volume has been changed, as these may need a remount to take affect. While this is semantically equivalent with unmounting and then remounting not all backends might need to actually be unmounted.

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 GAsyncReadyCallback, or None.

do_remount_finish

def do_remount_finish(self, result: AsyncResult) -> bool

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

Parameters:

do_unmount

def do_unmount(self, flags: MountUnmountFlags | int, cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

:::warning Deprecated since 2.22 This API is deprecated. :::

Unmounts a mount. This is an asynchronous operation, and is finished by calling Mount.unmount_finish with the mount and AsyncResult data returned in the callback.

Parameters:

  • flags — flags affecting the operation
  • cancellable — optional Cancellable object, None to ignore.
  • callback — a GAsyncReadyCallback, or None.

do_unmount_finish

def do_unmount_finish(self, result: AsyncResult) -> bool

:::warning Deprecated since 2.22 This API is deprecated. :::

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

Parameters:

do_unmount_with_operation

def do_unmount_with_operation(self, flags: MountUnmountFlags | int, mount_operation: MountOperation | None = ..., cancellable: Cancellable | None = ..., callback: Callable[[Mount | None, AsyncResult], None] | None = ...) -> None

Unmounts a mount. This is an asynchronous operation, and is finished by calling Mount.unmount_with_operation_finish with the mount and AsyncResult data 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 GAsyncReadyCallback, or None.

do_unmount_with_operation_finish

def do_unmount_with_operation_finish(self, result: AsyncResult) -> bool

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

Parameters:

do_unmounted

def do_unmounted(self) -> None

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

Signals

changed

def on_changed(self) -> None: ...

Emitted when the mount has been changed.

pre-unmount

def on_pre_unmount(self) -> None: ...

This signal may be emitted when the Mount is about to be unmounted.

This signal depends on the backend and is only emitted if GIO was used to unmount.

unmounted

def on_unmounted(self) -> None: ...

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