Added option to skip autodetection of filesystem. This is so for instance luks2() can override any auto-detection that revers back to the parent device of the mapped device, which would be crypto_LUKS instead of None for the inner partition.

This commit is contained in:
Anton Hvornum 2021-03-09 12:16:40 +01:00
parent 585e0f4b86
commit 8f42a9f4ff
2 changed files with 6 additions and 7 deletions

View File

@ -130,7 +130,7 @@ class BlockDevice():
return False
class Partition():
def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False):
def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True):
if not part_id:
part_id = os.path.basename(path)
self.path = path
@ -152,8 +152,10 @@ class Partition():
if (target := mount_information.get('target', None)):
self.mountpoint = target
if not self.filesystem and (fstype := mount_information.get('fstype', get_filesystem_type(self.real_device))):
self.filesystem = fstype
if not self.filesystem and autodetect_filesystem:
if (fstype := mount_information.get('fstype', get_filesystem_type(self.real_device))):
self.filesystem = fstype
if self.filesystem == 'crypto_LUKS':
self.encrypted = True

View File

@ -83,10 +83,7 @@ class luks2():
os.path.basename(mountpoint) # TODO: Raise exception instead?
sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2')
if os.path.islink(f'/dev/mapper/{mountpoint}'):
self.mapdev = f'/dev/mapper/{mountpoint}'
inner_fs = get_filesystem_type(self.mapdev)
print('Inner FS:', inner_fs)
return Partition(self.mapdev, encrypted=True, filesystem=inner_fs)
return Partition(self.mapdev, encrypted=True, filesystem=get_filesystem_type(self.mapdev), autodetect_filesystem=False)
def close(self, mountpoint=None):
if not mountpoint: