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
This commit is contained in:
2Shirt 2021-03-18 22:02:57 -06:00
parent 7c1a9f4bdc
commit 207c52663b
2 changed files with 18 additions and 7 deletions

View file

@ -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,
)

View file

@ -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"]}'))