Class StorageDevice
UdevDevice and provides easy access to storage specific data.
A storage device represents a partition on a storage device that can be mounted.
Devices aren't automatically mounted when detected. This allows devices to be
inserted and removed without impact and only be mounted for the duration of a
particular operation. This minimizes the chances of a user pulling a removable
device while the device is mounted and in operation.
Devices can be mounted and unmounted using the mount() and unmount()
methods. Mounts are use counted so mounting an already mounted device will simply
bump the use count. Similarly, the device is only unmounted when the use count
reaches zero. This allows multiple systems to use the mount at the same time
without worrying that it will be unmounted during use. This also means that every
mount call must have a matching unmount call.
The actual mount location for this device when mounted can is available via
getMountDir(). This directory will only exists while the device is
mounted and will be removed when the device is unmounted. This path is relative
to the node the device is attached to so will not be accessible via the local
filesystem if the device is on a different node.
If the device is removed or the node the device is attached to disconnects, the device object will be orphaned and garbage collected once no longer referenced. Any mount / unmount calls will appear to work until the use count reaches zero after which mounting will no longer work.
- Since:
- 1.0
- Version:
- 2024-04-30
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetId()Return the id of the device.getLabel()Return label of the partition.getModel()Return model of the device.Return the directory the device is mounted at.Return the nodeId the device is attached to.longReturn how long the device has been running in ms.Return information about the mounted storage.Return the syspath of the device.Return vendor name of the device.booleanisLocal()Return true if the device is attached to the local node.booleanReturn true if the device is removed.mount()Mount the storage withMountOption.USBwhich is a collection of options geared towards security and minimizing file corruption on device removal.mount(int mountOptions) Mount the storage with the specified mount options.Mount the storage with the specified mount and filesystem options.toString()voidunmount()Unmount the storage
-
Constructor Details
-
StorageDevice
public StorageDevice()
-
-
Method Details
-
getId
Return the id of the device. -
getSyspath
Return the syspath of the device. This uniquely defines the device and can be used as a device key. -
getRunTimeMs
public long getRunTimeMs()Return how long the device has been running in ms. -
getVendor
Return vendor name of the device. -
getModel
Return model of the device. -
getLabel
Return label of the partition. -
getMountDir
Return the directory the device is mounted at. This returns null unless the storage is mounted viamount(). Once unmounted, this will return to null. -
isRemoved
public boolean isRemoved()Return true if the device is removed. This will be true if the device is removed or if the node the device is attached to disconnects. The mount and unmount calls will continue to function as expected until the use count on the mount reaches zero. This can be used to detect if operations on the mounted filesystem will fail even though it appears to be mounted. -
getNodeId
Return the nodeId the device is attached to. -
isLocal
public boolean isLocal()Return true if the device is attached to the local node. -
getStorageInfo
Return information about the mounted storage. Returns null if the device isn't mounted. If mounted, this will fetch the latest information from the device.- Throws:
IOException
-
mount
Mount the storage withMountOption.USBwhich is a collection of options geared towards security and minimizing file corruption on device removal.If the device is already mounted, this simply bumps the use count and the options will be ignored.
- Throws:
IOException
-
mount
Mount the storage with the specified mount options.If the device is already mounted, this simply bumps the use count and the options will be ignored.
- Parameters:
mountOptions- logical OR of variousMountOptionconstants- Throws:
IOException
-
mount
Mount the storage with the specified mount and filesystem options.If the device is already mounted, this simply bumps the use count and the options will be ignored.
- Parameters:
mountOptions- logical OR of variousMountOptionconstantsfilesystemOptions- comma separated list of filesystem specific options- Throws:
IOException- of the mount fails
-
unmount
public void unmount()Unmount the storage -
toString
-
getStorageService
-
getUdevDevice
-
getListeners
-