Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Avoid self-owned disk false positive during CFW install

Lakr9d12c106c91d
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index e56081d8..dfaffadb 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -93,9 +93,11 @@ struct VPhoneCustomFirmwareInstaller {
let disk = try openDiskImage(in: bundleDirectory, path: bundlePath, owner: callerUID)
let diskPath = (bundlePath as NSString).appendingPathComponent("Disk.img")
let busy = try VPhoneProcessRunner.runCapturing(
- URL(fileURLWithPath: "/usr/sbin/lsof"), [diskPath],
+ URL(fileURLWithPath: "/usr/sbin/lsof"), ["-t", "--", diskPath],
)
- guard busy.stdout.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
+ // openDiskImage holds our verified descriptor throughout the install,
+ // so lsof always lists this process even when the VM is stopped.
+ guard !VPhoneLsof.parsePIDs(busy.stdout).contains(where: { $0 != getpid() }) else {
throw ValidationError("The VM disk is in use. Stop the VM, then install CFW again.")
}
let restore = try restoreTree(in: bundleDirectory, path: bundlePath, owner: callerUID)