Skip to content

Commit

Permalink
osenum: Add more logging
Browse files Browse the repository at this point in the history
Signed-off-by: Hector Martin <marcan@marcan.st>
  • Loading branch information
marcan committed Mar 1, 2022
1 parent 34135ad commit e3d26f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/diskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def __init__(self):
self.verbose = "-v" in sys.argv

def action(self, *args, verbose=False):
logging.info(f"run: diskutil {args!r}")
logging.debug(f"run: diskutil {args!r}")
subprocess.run(["diskutil"] + list(args), check=True, capture_output=(not self.verbose))

def get(self, *args):
logging.info(f"get: diskutil {args!r}")
logging.debug(f"get: diskutil {args!r}")
result = subprocess.run(["diskutil"] + list(args),
stdout=subprocess.PIPE, check=True)
return plistlib.loads(result.stdout)
Expand Down
30 changes: 23 additions & 7 deletions src/osenum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
import os, os.path, plistlib, subprocess
import os, os.path, plistlib, subprocess, logging
from dataclasses import dataclass

UUID_SROS = "3D3287DE-280D-4619-AAAB-D97469CA9C71"
Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(self, sysinfo, dutil, sysdsk):
self.sysdsk = sysdsk

def collect(self, parts):
logging.info("OSEnum.collect()")
for p in parts:
p.os = []
if p.type == "Apple_APFS_Recovery":
Expand All @@ -57,6 +58,7 @@ def collect(self, parts):
self.collect_part(p)

def collect_recovery(self, part):
logging.info(f"OSEnum.collect_recovery(part={part.name})")
recs = []

for volume in part.container["Volumes"]:
Expand All @@ -66,14 +68,19 @@ def collect_recovery(self, part):
if len(recs) != 1:
return

part.os.append(OSInfo(partition=part, vgid=UUID_SROS,
rec_vgid=recs[0]["APFSVolumeUUID"],
version=self.sysinfo.sfr_ver))
os = OSInfo(partition=part, vgid=UUID_SROS,
rec_vgid=recs[0]["APFSVolumeUUID"],
version=self.sysinfo.sfr_ver)
logging.info(f" Found SROS: {os}")
part.os.append(os)
if self.sysinfo.fsfr_ver:
part.os.append(OSInfo(partition=part, vgid=UUID_FROS,
version=self.sysinfo.fsfr_ver))
os = OSInfo(partition=part, vgid=UUID_FROS,
version=self.sysinfo.fsfr_ver)
logging.info(f" Found FROS: {os}")
part.os.append(os)

def collect_part(self, part):
logging.info(f"OSEnum.collect_part(part={part.name})")
if part.container is None:
return

Expand All @@ -92,25 +99,31 @@ def collect_part(self, part):
for role in ("Preboot", "Recovery"):
vols = by_role.get((role,), None)
if not vols:
logging.info(f" No {role} volume")
return
elif len(vols) > 1:
logging.info(f" Multiple {role} volumes ({vols})")
return
volumes[role] = vols[0]

for vg in ct["VolumeGroups"]:
data = [i for i in vg["Volumes"] if i["Role"] == "Data"]
system = [i for i in vg["Volumes"] if i["Role"] == "System"]
if len(data) != 1 or len(system) != 1:
logging.info(f" Weird VG: {vg['Volumes']}")
continue

volumes["Data"] = by_device[data[0]["DeviceIdentifier"]]
volumes["System"] = by_device[system[0]["DeviceIdentifier"]]
vgid = vg["APFSVolumeGroupUUID"]
part.os.append(self.collect_os(part, volumes, vgid))
os = self.collect_os(part, volumes, vgid)
logging.info(f" Found {os}")
part.os.append(os)

return part.os

def collect_os(self, part, volumes, vgid):
logging.info(f"OSEnum.collect_os(part={part.name}, vgid={vgid})")
mounts = {}

for role in ("Preboot", "Recovery", "System"):
Expand Down Expand Up @@ -148,6 +161,7 @@ def collect_os(self, part, volumes, vgid):
try:
bps = self.bputil("-d", "-v", vgid)
except subprocess.CalledProcessError:
logging.info(f" bputil failed")
return osi

osi.bp = {}
Expand All @@ -158,6 +172,7 @@ def collect_os(self, part, volumes, vgid):
if val == "absent":
val = None
osi.bp[k] = val
logging.info(f" BootPolicy[{k}] = {val}")

if coih := osi.bp.get("coih", None):
fuos_path = os.path.join(mounts["Preboot"], vgid, "boot",
Expand All @@ -167,6 +182,7 @@ def collect_os(self, part, volumes, vgid):
fuos = open(fuos_path, "rb").read()
if b"##m1n1_ver##" in fuos:
osi.m1n1_ver = fuos.split(b"##m1n1_ver##")[1].split(b"\0")[0].decode("ascii")
logging.info(f" m1n1 version found: {osi.m1n1_ver}")

return osi

Expand Down

0 comments on commit e3d26f7

Please sign in to comment.