Interface Volume

All Superinterfaces:
Proxy
All Known Implementing Classes:
Volume.Volume$Impl

@Generated("org.javagi.JavaGI") public interface Volume extends Proxy

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 getMount().

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(Set, MountOperation, Cancellable, AsyncReadyCallback) with (at least) the GVolume instance, optionally a MountOperation object and a Gio.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 mountFinish(AsyncResult) with the GVolume instance and the AsyncResult data to see if the operation was completed successfully. If a GLib.Error is present when mountFinish(AsyncResult) 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 getIdentifier(String) 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().

  • Method Details

    • getType

      static @Nullable Type getType()
      Get the GType of the Volume class.
      Returns:
      the GType
    • canEject

      default boolean canEject()
      Checks if a volume can be ejected.
      Returns:
      true if the this Volume can be ejected. false otherwise
    • canMount

      default boolean canMount()
      Checks if a volume can be mounted.
      Returns:
      true if the this Volume can be mounted. false otherwise
    • eject

      @Deprecated default void eject(Set<MountUnmountFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Deprecated.
      Use g_volume_eject_with_operation() instead.
      Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_finish() with the this Volume and GAsyncResult returned in the callback.
      Parameters:
      flags - flags affecting the unmount if required for eject
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
    • eject

      @Deprecated default void eject(MountUnmountFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Deprecated.
      Use g_volume_eject_with_operation() instead.
      Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_finish() with the this Volume and GAsyncResult returned in the callback.
      Parameters:
      flags - flags affecting the unmount if required for eject
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
    • ejectFinish

      @Deprecated default boolean ejectFinish(AsyncResult result) throws GErrorException
      Deprecated.
      Use g_volume_eject_with_operation_finish() instead.
      Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and false will be returned.
      Parameters:
      result - a GAsyncResult
      Returns:
      true, false if operation failed
      Throws:
      GErrorException - see GError
    • ejectWithOperation

      default void ejectWithOperation(Set<MountUnmountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_with_operation_finish() with the this Volume and GAsyncResult data returned in the callback.
      Parameters:
      flags - flags affecting the unmount if required for eject
      mountOperation - a GMountOperation or null to avoid user interaction
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
      Since:
      2.22
    • ejectWithOperation

      default void ejectWithOperation(MountUnmountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Ejects a volume. This is an asynchronous operation, and is finished by calling g_volume_eject_with_operation_finish() with the this Volume and GAsyncResult data returned in the callback.
      Parameters:
      flags - flags affecting the unmount if required for eject
      mountOperation - a GMountOperation or null to avoid user interaction
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
      Since:
      2.22
    • ejectWithOperationFinish

      default boolean ejectWithOperationFinish(AsyncResult result) throws GErrorException
      Finishes ejecting a volume. If any errors occurred during the operation, error will be set to contain the errors and false will be returned.
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the volume was successfully ejected. false otherwise
      Throws:
      GErrorException - see GError
      Since:
      2.22
    • enumerateIdentifiers

      default String[] enumerateIdentifiers()
      Gets the kinds of identifiers that this Volume has. Use g_volume_get_identifier() to obtain the identifiers themselves.
      Returns:
      a null-terminated array of strings containing kinds of identifiers. Use g_strfreev() to free.
    • getActivationRoot

      default @Nullable File getActivationRoot()

      Gets the activation root for a GVolume if it is known ahead of mount time. Returns null otherwise. If not null and if this 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

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

      Returns:
      the activation root of this Volume or null. Use g_object_unref() to free.
      Since:
      2.18
    • getDrive

      default @Nullable Drive getDrive()
      Gets the drive for the volume.
      Returns:
      a GDrive or null if this Volume is not associated with a drive. The returned object should be unreffed with g_object_unref() when no longer needed.
    • getIcon

      default Icon getIcon()
      Gets the icon for volume.
      Returns:
      a GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.
    • getIdentifier

      default @Nullable String getIdentifier(String kind)
      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
      Returns:
      a newly allocated string containing the requested identifier, or null if the GVolume doesn't have this kind of identifier
    • getMount

      default @Nullable Mount getMount()
      Gets the mount for the volume.
      Returns:
      a GMount or null if this Volume isn't mounted. The returned object should be unreffed with g_object_unref() when no longer needed.
    • getName

      default String getName()
      Gets the name of volume.
      Returns:
      the name for the given volume. The returned string should be freed with g_free() when no longer needed.
    • getSortKey

      default @Nullable String getSortKey()
      Gets the sort key for volume, if any.
      Returns:
      Sorting key for this Volume or null if no such key is available
      Since:
      2.32
    • getSymbolicIcon

      default Icon getSymbolicIcon()
      Gets the symbolic icon for volume.
      Returns:
      a GIcon. The returned object should be unreffed with g_object_unref() when no longer needed.
      Since:
      2.34
    • getUuid

      default @Nullable String getUuid()
      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 null if there is no UUID available.
      Returns:
      the UUID for this Volume or null if no UUID can be computed. The returned string should be freed with g_free() when no longer needed.
    • mount

      default void mount(Set<MountMountFlags> flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume and GAsyncResult returned in the callback.
      Parameters:
      flags - flags affecting the operation
      mountOperation - a GMountOperation or null to avoid user interaction
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
    • mount

      default void mount(MountMountFlags flags, @Nullable MountOperation mountOperation, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Mounts a volume. This is an asynchronous operation, and is finished by calling g_volume_mount_finish() with the this Volume and GAsyncResult returned in the callback.
      Parameters:
      flags - flags affecting the operation
      mountOperation - a GMountOperation or null to avoid user interaction
      cancellable - optional GCancellable object, null to ignore
      callback - a GAsyncReadyCallback, or null
    • mountFinish

      default boolean mountFinish(AsyncResult result) throws GErrorException

      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, g_volume_get_mount() on this Volume is guaranteed to return the mount right after calling this function; there's no need to listen for the 'mount-added' signal on GVolumeMonitor.

      Parameters:
      result - a GAsyncResult
      Returns:
      true, false if operation failed
      Throws:
      GErrorException - see GError
    • shouldAutomount

      default boolean shouldAutomount()
      Returns whether the volume should be automatically mounted.
      Returns:
      true if the volume should be automatically mounted
    • onChanged

      Emitted when the volume has been changed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      default void emitChanged()
      Emits the "changed" signal. See onChanged(Volume.ChangedCallback).
    • onRemoved

      This signal is emitted when the GVolume have been removed. If the recipient is holding references to the object they should release them so the object can be finalized.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitRemoved

      default void emitRemoved()
      Emits the "removed" signal. See onRemoved(Volume.RemovedCallback).