From d3b5143ed6659ad826f17ba5aae7c80c4a4650e7 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 2 Jun 2020 17:15:45 -0700 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/modules/storage/udisks2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plinth/modules/storage/udisks2.py b/plinth/modules/storage/udisks2.py index 794ca2464..466bce0f4 100644 --- a/plinth/modules/storage/udisks2.py +++ b/plinth/modules/storage/udisks2.py @@ -74,6 +74,9 @@ class Proxy: if value is None: return value + if signature.startswith('a('): + return value + if signature == 'ay': return bytes(value)[:-1].decode() @@ -96,6 +99,7 @@ class BlockDevice(Proxy): """Abstraction for UDisks2 Block device.""" interface = _INTERFACES['Block'] properties = { + 'configuration': ('a(sa{sv})', 'Configuration'), 'crypto_backing_device': ('o', 'CryptoBackingDevice'), 'device': ('ay', 'Device'), 'hint_ignore': ('b', 'HintIgnore'), @@ -131,6 +135,16 @@ class Loop(Proxy): 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(): """List devices that can be ejected.""" devices = [] @@ -151,7 +165,7 @@ def get_disks(): 'label': block.id_label, 'size': block.size, 'filesystem_type': block.id_type, - 'is_removable': not block.hint_system, + 'is_removable': _is_removable(object_), 'mount_points': [], } try: