From 207c52663b5016bb4c67d79c3fc1b61a6d51a135 Mon Sep 17 00:00:00 2001 From: 2Shirt Date: Thu, 18 Mar 2021 22:02:57 -0600 Subject: [PATCH] Allow mounting of protected macOS partitions Renamed mount_volumes() to mount_disk() to better match diskutil naming. Dropped read_write from mount_disk() since it isn't used --- scripts/wk/hw/diags.py | 2 +- scripts/wk/os/mac.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index 8ec70963..7692b58c 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -1394,7 +1394,7 @@ def ost_generate_volume_report(dev): # OS Check if PLATFORM == 'Darwin': - vol_report = wk_os.mac.mount_volumes( + vol_report = wk_os.mac.mount_disk( device_path=dev.path, read_write=False, ) diff --git a/scripts/wk/os/mac.py b/scripts/wk/os/mac.py index d5735005..c3bdca84 100644 --- a/scripts/wk/os/mac.py +++ b/scripts/wk/os/mac.py @@ -57,6 +57,7 @@ def get_apfs_volumes(device_path): # Add volumes for container in containers: for volume in container['Volumes']: + mount_volume(volume['DeviceIdentifier']) volumes.append(Disk(f'/dev/{volume["DeviceIdentifier"]}')) # Done @@ -125,15 +126,29 @@ def get_core_storage_volumes(device_path): continue if 'Partitions' in disk_data: for part in disk_data['Partitions']: + mount_volume(part['DeviceIdentifier']) volumes.append(Disk(f'/dev/{part["DeviceIdentifier"]}')) elif 'VolumeName' in disk_data: + mount_volume(disk_data['DeviceIdentifier']) volumes.append(Disk(f'/dev/{disk_data["DeviceIdentifier"]}')) # Done return volumes -def mount_volumes(device_path=None, read_write=False): +def mount_volume(volume_path, read_only=True): + """Try to mount a volume, returns subprocess.CompletedProcess.""" + cmd = ['sudo', 'diskutil', 'mount'] + if read_only: + cmd.append('readOnly') + cmd.append(volume_path) + proc = run_program(cmd, check=False) + + # Done + return proc + + +def mount_disk(device_path=None): """Mount all detected volumes, returns list. NOTE: If device_path is specified then only volumes @@ -160,11 +175,7 @@ def mount_volumes(device_path=None, read_write=False): # Mount and add volumes for part in plist_data['AllDisksAndPartitions'][0]['Partitions']: - cmd = ['diskutil', 'mount', 'readOnly', part['DeviceIdentifier']] - if read_write: - # NOTE: Unused 2021-03 - cmd.pop(2) - proc = run_program(cmd, check=False) + proc = mount_volume(part['DeviceIdentifier']) # Add volume volumes.append(Disk(f'/dev/{part["DeviceIdentifier"]}'))