storage: Allow ejecting any device not in fstab or crypttab

Allow any disk including SATA disks to be ejected.

Helps: #1597.

Tests performed:

- Attach SATA disk to VirtualBox. Create two partitions and filesystem in it.
FreedomBox will auto-mount the filesystems. Eject button is shown on both the
partitions. Without the patch, this is not shown.

- Eject button is not shown against '/' as it is part of fstab.

- Add a device into /etc/fstab. Eject button will not be shown against the
device.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-06-02 17:15:45 -07:00 committed by James Valleroy
parent 426cef4c2c
commit d3b5143ed6
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -74,6 +74,9 @@ class Proxy:
if value is None: if value is None:
return value return value
if signature.startswith('a('):
return value
if signature == 'ay': if signature == 'ay':
return bytes(value)[:-1].decode() return bytes(value)[:-1].decode()
@ -96,6 +99,7 @@ class BlockDevice(Proxy):
"""Abstraction for UDisks2 Block device.""" """Abstraction for UDisks2 Block device."""
interface = _INTERFACES['Block'] interface = _INTERFACES['Block']
properties = { properties = {
'configuration': ('a(sa{sv})', 'Configuration'),
'crypto_backing_device': ('o', 'CryptoBackingDevice'), 'crypto_backing_device': ('o', 'CryptoBackingDevice'),
'device': ('ay', 'Device'), 'device': ('ay', 'Device'),
'hint_ignore': ('b', 'HintIgnore'), 'hint_ignore': ('b', 'HintIgnore'),
@ -131,6 +135,16 @@ class Loop(Proxy):
properties = {'backing_file': ('ay', 'BackingFile')} properties = {'backing_file': ('ay', 'BackingFile')}
def _is_removable(object_path):
"""Return True if the device is not part of fstab or crypttab."""
block = BlockDevice(object_path)
for type_, _details in block.configuration:
if type_ in ('fstab', 'crypttab'):
return False
return True
def get_disks(): def get_disks():
"""List devices that can be ejected.""" """List devices that can be ejected."""
devices = [] devices = []
@ -151,7 +165,7 @@ def get_disks():
'label': block.id_label, 'label': block.id_label,
'size': block.size, 'size': block.size,
'filesystem_type': block.id_type, 'filesystem_type': block.id_type,
'is_removable': not block.hint_system, 'is_removable': _is_removable(object_),
'mount_points': [], 'mount_points': [],
} }
try: try: