Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Replace deprecated hdiutil calls with diskutil

Phineas Guo07686400897d
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 3ee90ebc..d6c92289 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -2812,3 +2812,31 @@ persona-fetch authorization. Adding a temporary exception entitlement was
verified ineffective on the running guest and has been removed. IDA analysis
of this guest's launchd confirms the bootstrap lookup gate and name filters
2, 3 and 12. See [evidence, implementation and validation](Guest/ios27_xcode_persona_lookup.md).
+
+## Host disk-image command migration (2026-10-08)
+
+The migration replaces `hdiutil` because macOS 27 marks it as deprecated.
+The system's `hdiutil(1)` manual recommends `diskutil image`, and command help
+prints deprecation warnings directing attach, detach and convert operations
+to `diskutil image attach`, `diskutil eject` and `diskutil image create from`.
+
+No guest binary patch or preset change. On macOS 15+, CFW install and kernel
+update, PCC GPU recovery, seal-tool extraction and Cryptex filesystem attachment
+use `diskutil image attach`. Writable conversion uses `diskutil image create
+from -format RAW`, which `diskutil(8)` identifies as the former UDRW format.
+There is no hdiutil fallback or new disk-image tool abstraction: calls stay in
+their existing functions. The macOS 15 `diskutil(8)` system manual already
+documents image attach, create and resize. Single-hyphen options
+preserve compatibility with older diskutil versions; conversion supplies
+`-source` on macOS 15 and a positional source on macOS 26+. Existing function
+names and CLI arguments are preserved. Eject uses `diskutil eject`; a busy image is
+retried after `diskutil unmountDisk force`, avoiding the newer `eject force`
+syntax on older systems. Attachment parsing retains the physical APFS store's
+parent disk even when a synthesized container is reported first, and keeps
+mount points containing spaces intact. PCC recovery tracks successful eject
+before deleting its temporary library instead of querying `hdiutil info`.
+
+`CryptexFileOpsTests`: all 12 existing tests pass. The
+`VPhone` bundle build and bundle admission pass on macOS 27.0.1 / Xcode 27.1.
+Real image attachment and execution on macOS 15 still require live validation;
+no VM disk is modified by the validation tests.
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherDiskImage.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherDiskImage.swift
index 09995f68..29e47502 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherDiskImage.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherDiskImage.swift
@@ -1,6 +1,6 @@
// CryptexFilesystemPatcherDiskImage.swift — Disk image attach, convert and copy helpers.
//
-// Split out of CryptexFilesystemPatcher.swift. The hdiutil/diskutil layer: attaching and
+// Split out of CryptexFilesystemPatcher.swift. The diskutil layer: attaching and
// detaching images, converting between RAW and UDRW, resizing, unmounting, and the
// copyfile-based volume copy used to merge a cryptex into the target volume.
@@ -65,11 +65,12 @@ extension CryptexFilesystemPatcher {
}
func convertToRawImage(input: URL, output: URL) throws {
- _ = try runProcess("/usr/sbin/diskutil", [
- "image", "create", "from",
- "--format", "RAW", input.path,
- output.path,
- ])
+ let arguments = if #available(macOS 26, *) {
+ ["image", "create", "from", "-format", "RAW", input.path, output.path]
+ } else {
+ ["image", "create", "from", "-format", "RAW", "-source", input.path, output.path]
+ }
+ _ = try runProcess("/usr/sbin/diskutil", arguments)
// Resize to max. Asking diskutil how big it may get returns a plist, and
// reading one value out of it used to be `/bin/sh -c "… | plutil -extract
@@ -77,11 +78,11 @@ extension CryptexFilesystemPatcher {
// can read directly — and a pipeline whose stdout is also where diskutil's
// own warnings land, so a noisy run produced a "size" that was a sentence.
let sizes = try runProcess("/usr/sbin/diskutil", [
- "image", "resize", "--plist", output.path,
+ "image", "resize", "-plist", output.path,
])
let maxsize = try Self.maxResizeSize(fromDiskutilPlist: sizes)
_ = try runProcess("/usr/sbin/diskutil", [
- "image", "resize", "--size", maxsize, output.path,
+ "image", "resize", "-size", maxsize, output.path,
])
}
@@ -114,19 +115,20 @@ extension CryptexFilesystemPatcher {
if FileManager.default.fileExists(atPath: output.path) {
try FileManager.default.removeItem(at: output)
}
- _ = try runProcess("/usr/bin/hdiutil", [
- "convert",
- input.path,
- "-format", "UDRW",
- "-o", output.path,
- ])
+ // diskutil calls the former UDRW read-write format RAW.
+ let arguments = if #available(macOS 26, *) {
+ ["image", "create", "from", "-format", "RAW", input.path, output.path]
+ } else {
+ ["image", "create", "from", "-format", "RAW", "-source", input.path, output.path]
+ }
+ _ = try runProcess("/usr/sbin/diskutil", arguments)
}
func shrinkImage(dmg: URL) throws {
_ = try runProcess("/usr/sbin/diskutil", [
"image",
"resize",
- "--size", "min",
+ "-size", "min",
dmg.path,
])
}
@@ -138,18 +140,16 @@ extension CryptexFilesystemPatcher {
/// attachImage returns the device and mount point
func attachImage(path: URL, readonly: Bool = false, forceRW: Bool = false) throws -> (String, String) {
let process = Process()
- process.executableURL = URL(fileURLWithPath: "/usr/bin/hdiutil")
+ process.executableURL = URL(fileURLWithPath: "/usr/sbin/diskutil")
process.arguments = if readonly {
[
- "attach",
- "-readonly",
- "-plist",
+ "image", "attach",
+ "-readOnly",
path.path,
]
} else {
[
- "attach",
- "-plist",
+ "image", "attach",
path.path,
]
}
@@ -168,27 +168,15 @@ extension CryptexFilesystemPatcher {
throw ProcessError.failed(process.terminationStatus, output)
}
- let root: PlistDict
- do {
- root = try parsePlist(data: data)
- } catch {
- detachReportedImage(in: String(data: data, encoding: .utf8) ?? "")
- throw error
- }
- guard let entries = root["system-entities"] as? [Any] else {
- detachReportedImage(in: String(data: data, encoding: .utf8) ?? "")
- throw FirmwareManifest.ManifestError.missingKey("system-entities")
- }
- for entry in entries {
- guard let entry = entry as? PlistDict,
- let volumeKind = entry["volume-kind"] as? String,
- volumeKind == "apfs" || volumeKind == "hfs"
- else {
+ let output = String(decoding: data, as: UTF8.self)
+ for line in output.split(whereSeparator: \.isNewline) {
+ let fields = line.split(separator: "\t", omittingEmptySubsequences: false)
+ .map { $0.trimmingCharacters(in: .whitespaces) }
+ guard fields.count >= 3, fields[0].hasPrefix("/dev/disk"), fields[2].hasPrefix("/") else {
continue
}
- let device = entry["dev-entry"] as? String ?? ""
- let mountPoint = entry["mount-point"] as? String ?? ""
- guard !device.isEmpty, !mountPoint.isEmpty else { continue }
+ let device = fields[0]
+ let mountPoint = fields[2]
attachedDevices.insert(device)
if forceRW {
@@ -216,9 +204,10 @@ extension CryptexFilesystemPatcher {
func detachImage(deviceNode: String) throws {
do {
- _ = try runProcess("/usr/bin/hdiutil", ["detach", deviceNode])
+ _ = try runProcess("/usr/sbin/diskutil", ["eject", deviceNode])
} catch {
- _ = try runProcess("/usr/bin/hdiutil", ["detach", "-force", deviceNode])
+ _ = try runProcess("/usr/sbin/diskutil", ["unmountDisk", "force", deviceNode])
+ _ = try runProcess("/usr/sbin/diskutil", ["eject", deviceNode])
}
attachedDevices.remove(deviceNode)
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherProcess.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherProcess.swift
index 659b2714..a6498570 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherProcess.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherProcess.swift
@@ -1,6 +1,6 @@
// CryptexFilesystemPatcherProcess.swift — Subprocess execution for the filesystem patcher.
//
-// Split out of CryptexFilesystemPatcher.swift. Every external tool the merge drives — hdiutil,
+// Split out of CryptexFilesystemPatcher.swift. Every external tool the merge drives —
// diskutil, ipsw, aa, cryptexctl, apfs_sealvolume — runs through runProcess, and ProcessError
// is what it throws. What no longer runs through it: tar (VPhoneArchiveKit), and chmod, chown, ln
// and find (CryptexFilesystemPatcherFileOps.swift).
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index 44de3aed..581e17ac 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -218,9 +218,9 @@ struct VPhoneCustomFirmwareInstaller {
} else {
// Another volume, or no clone support: attach the caller's file
// in place. Confirm the name still refers to the inode verified
- // above immediately before hdiutil opens it. A swap in the moment
- // between this check and hdiutil's own open remains possible,
- // and hdiutil then works on the caller's own replacement. The
+ // above immediately before diskutil opens it. A swap in the moment
+ // between this check and diskutil's own open remains possible,
+ // and diskutil then works on the caller's own replacement. The
// snapshot rename below writes only the verified inode. The clone
// path, the normal case on APFS, has no such window.
guard try bundleDirectory.refersTo("Disk.img", file: disk) else {
@@ -233,12 +233,12 @@ struct VPhoneCustomFirmwareInstaller {
}
let attached = try tool(
- "/usr/bin/hdiutil",
+ "/usr/sbin/diskutil",
[
- "attach", "-nomount", "-imagekey", "diskimage-class=CRawDiskImage", image.path,
+ "image", "attach", "-noMount", image.path,
],
)
- // `hdiutil attach` prints the image's own disk and, on macOS 27, the APFS
+ // `diskutil image attach` prints the image's own disk and, on macOS 27, the APFS
// container it synthesizes over it before that disk, so its first line is
// no longer the image: the container's line carries the container's type
// and taking it would make every later device reference point at the
@@ -256,16 +256,18 @@ struct VPhoneCustomFirmwareInstaller {
} ?? wholeDisk ?? devices.first?.device
guard let baseDisk, baseDisk.hasPrefix("/dev/disk") else {
if let range = attached.range(of: #"/dev/disk[0-9]+"#, options: .regularExpression) {
- _ = try? tool("/usr/bin/hdiutil", ["detach", "-force", String(attached[range])], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["unmountDisk", "force", String(attached[range])], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["eject", String(attached[range])], quiet: true)
}
throw ValidationError("Unable to attach the VM disk image. Try again.")
}
var diskAttached = true
defer {
if diskAttached,
- (try? tool("/usr/bin/hdiutil", ["detach", baseDisk], quiet: true)) == nil
+ (try? tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)) == nil
{
- _ = try? tool("/usr/bin/hdiutil", ["detach", "-force", baseDisk], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["unmountDisk", "force", baseDisk], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)
}
}
@@ -414,7 +416,7 @@ struct VPhoneCustomFirmwareInstaller {
xartMounted = false
_ = try tool("/sbin/umount", [system.path])
systemMounted = false
- _ = try tool("/usr/bin/hdiutil", ["detach", baseDisk], quiet: true)
+ _ = try tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)
diskAttached = false
if mode == .full {
if cloned {
@@ -510,8 +512,8 @@ struct VPhoneCustomFirmwareInstaller {
}
let attached = try tool(
- "/usr/bin/hdiutil",
- ["attach", "-nomount", "-imagekey", "diskimage-class=CRawDiskImage", image.path],
+ "/usr/sbin/diskutil",
+ ["image", "attach", "-noMount", image.path],
)
let devices = attached.split(whereSeparator: \.isNewline).compactMap { line -> (device: String, type: String)? in
let fields = line.split(whereSeparator: \.isWhitespace)
@@ -525,16 +527,18 @@ struct VPhoneCustomFirmwareInstaller {
} ?? wholeDisk ?? devices.first?.device
guard let baseDisk, baseDisk.hasPrefix("/dev/disk") else {
if let range = attached.range(of: #"/dev/disk[0-9]+"#, options: .regularExpression) {
- _ = try? tool("/usr/bin/hdiutil", ["detach", "-force", String(attached[range])], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["unmountDisk", "force", String(attached[range])], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["eject", String(attached[range])], quiet: true)
}
throw ValidationError("Unable to attach the VM disk image. Try again.")
}
var diskAttached = true
defer {
if diskAttached,
- (try? tool("/usr/bin/hdiutil", ["detach", baseDisk], quiet: true)) == nil
+ (try? tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)) == nil
{
- _ = try? tool("/usr/bin/hdiutil", ["detach", "-force", baseDisk], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["unmountDisk", "force", baseDisk], quiet: true)
+ _ = try? tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)
}
}
@@ -599,7 +603,7 @@ struct VPhoneCustomFirmwareInstaller {
_ = try tool("/sbin/umount", [mount.path])
prebootMounted = false
- _ = try tool("/usr/bin/hdiutil", ["detach", baseDisk], quiet: true)
+ _ = try tool("/usr/sbin/diskutil", ["eject", baseDisk], quiet: true)
diskAttached = false
// No snapshot rename: the kernelcache is read from Preboot, not from the
// System volume's root snapshot, so nothing on System changed.
@@ -1656,17 +1660,16 @@ struct VPhoneCustomFirmwareInstaller {
return work.file(name)
}
- /// Cryptex images are only read from. hdiutil applies nosuid to disk
- /// image mounts itself and does not take mount options, so the other
- /// guards are the read-only attach, the mount point inside the root-only
+ /// Cryptex images are only read from. Keep noowners and nosuid mount
+ /// options, the read-only attach, the mount point inside the root-only
/// work folder, and `copyTree`, which never follows a link and refuses
/// device nodes.
private func attachCryptex(_ image: URL, at mountPoint: URL) throws {
try tool(
- "/usr/bin/hdiutil",
+ "/usr/sbin/diskutil",
[
- "attach", "-readonly", "-noautoopen", "-nobrowse", "-owners", "off",
- "-mountpoint", mountPoint.path, image.path,
+ "image", "attach", "-readOnly", "-nobrowse", "-mountOptions", "noowners,nosuid",
+ "-mountPoint", mountPoint.path, image.path,
],
quiet: true,
)
@@ -2551,9 +2554,10 @@ struct VPhoneCustomFirmwareInstaller {
private func detachImage(at mount: URL) throws {
do {
- _ = try tool("/usr/bin/hdiutil", ["detach", mount.path], quiet: true)
+ _ = try tool("/usr/sbin/diskutil", ["eject", mount.path], quiet: true)
} catch {
- _ = try tool("/usr/bin/hdiutil", ["detach", "-force", mount.path], quiet: true)
+ _ = try tool("/usr/sbin/diskutil", ["unmountDisk", "force", mount.path], quiet: true)
+ _ = try tool("/usr/sbin/diskutil", ["eject", mount.path], quiet: true)
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
index 1fde18f4..eafcd2fe 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
@@ -4,7 +4,7 @@
//
// ipsw download ipsw --device D --urls -> vphone-cli fw urls --device D
// ipsw download appledb --os macOS … +
-// ipsw img4 im4p extract + hdiutil -> vphone-cli fw seal-tool
+// ipsw img4 im4p extract + diskutil -> vphone-cli fw seal-tool
//
// The second was five steps in shell: resolve a macOS build for the iOS
// version, range-fetch BuildManifest.plist out of an 18 GB remote zip, read the
@@ -158,24 +158,25 @@ struct VPhoneFirmwareSealToolCommand: ParsableCommand {
/// Mount the ramdisk read-only and take the one file out of it.
private static func copyOut(of dmg: URL, to destination: URL, attached: inout Bool) throws {
- let output = try run("/usr/bin/hdiutil",
- ["attach", "-readonly", "-nobrowse", "-plist", dmg.path])
+ let output = try run("/usr/sbin/diskutil",
+ ["image", "attach", "-readOnly", "-nobrowse", dmg.path])
attached = true
- guard let plist = try PropertyListSerialization.propertyList(
- from: Data(output.utf8),
- format: nil,
- ) as? [String: Any],
- let entities = plist["system-entities"] as? [[String: Any]]
- else { throw VPhoneRemoteZip.Error.malformed("hdiutil returned no disk information") }
- let mount = entities.compactMap { $0["mount-point"] as? String }.first
- let device = entities.compactMap { $0["dev-entry"] as? String }.first
+ let entities = output.split(whereSeparator: \.isNewline).compactMap { line -> (device: String, mount: String?)? in
+ let fields = line.split(separator: "\t", omittingEmptySubsequences: false)
+ .map { $0.trimmingCharacters(in: .whitespaces) }
+ guard let device = fields.first, device.hasPrefix("/dev/disk") else { return nil }
+ let mount = fields.count > 2 && fields[2].hasPrefix("/") ? fields[2] : nil
+ return (device, mount)
+ }
+ let mount = entities.compactMap(\.mount).first
+ let device = entities.first?.device
guard let target = device ?? mount else {
- throw VPhoneRemoteZip.Error.malformed("hdiutil attached nothing that can be detached")
+ throw VPhoneRemoteZip.Error.malformed("diskutil attached nothing that can be detached")
}
let copied: Result<Void, Swift.Error> = Result {
guard let mount else {
- throw VPhoneRemoteZip.Error.malformed("hdiutil attached nothing with a mount point")
+ throw VPhoneRemoteZip.Error.malformed("diskutil attached nothing with a mount point")
}
let source = URL(fileURLWithPath: mount).appending(
path: "System/Library/Filesystems/apfs.fs/Contents/Resources/apfs_sealvolume",
@@ -185,9 +186,10 @@ struct VPhoneFirmwareSealToolCommand: ParsableCommand {
ofItemAtPath: destination.path)
}
do {
- try run("/usr/bin/hdiutil", ["detach", target])
+ try run("/usr/sbin/diskutil", ["eject", target])
} catch {
- try run("/usr/bin/hdiutil", ["detach", "-force", target])
+ try run("/usr/sbin/diskutil", ["unmountDisk", "force", target])
+ try run("/usr/sbin/diskutil", ["eject", target])
}
attached = false
try copied.get()
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift
index af613409..caed5a91 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift
@@ -40,12 +40,10 @@ enum VPhonePCCGPURecovery {
romSource: VPhoneBundleOperations.defaultROMSource(),
sepromSource: VPhoneBundleOperations.defaultSEPROMSource(),
), in: library)
+ var diskMayBeAttached = false
let temporaryRestore = vm.url.appending(path: "iPhonePCC_Restore")
defer {
- let diskImage = vm.url.appendingPathComponent("Disk.img")
- if let info = try? run("/usr/bin/hdiutil", ["info"]),
- !info.contains(diskImage.path)
- {
+ if !diskMayBeAttached {
try? fm.removeItem(at: temporaryLibrary)
} else {
fputs("warning: PCC disk image may still be attached; left \(temporaryLibrary.path)\n", stderr)
@@ -98,6 +96,7 @@ enum VPhonePCCGPURecovery {
try stageFromSystemDisk(
vm.url.appending(path: "Disk.img"),
into: restoreDirectory, expectedPlatformVersion: expectedPlatformVersion,
+ diskMayBeAttached: &diskMayBeAttached,
)
}
@@ -105,15 +104,17 @@ enum VPhonePCCGPURecovery {
_ diskImage: URL,
into restoreDirectory: URL,
expectedPlatformVersion: String,
+ diskMayBeAttached: inout Bool,
) throws {
let fm = FileManager.default
- let attached = try run("/usr/bin/hdiutil", [
- "attach", "-readonly", "-nomount", "-imagekey",
- "diskimage-class=CRawDiskImage", diskImage.path,
+ // A failed attach can still leave a device. Only a successful eject
+ // permits deleting the temporary VM library.
+ diskMayBeAttached = true
+ let attached = try run("/usr/sbin/diskutil", [
+ "image", "attach", "-readOnly", "-noMount", diskImage.path,
])
- // macOS 27 prints the synthesized APFS container before the image's own
- // disk, so the first line is not the disk to detach later; take the disk
- // that carries the store partition. See VPhoneCustomFirmwareInstaller.
+ // The synthesized APFS container can precede the image disk. Take
+ // the parent of the store partition, as the CFW installer does.
let devices = attached.split(whereSeparator: \.isNewline).compactMap { line -> (device: String, type: String)? in
let fields = line.split(whereSeparator: \.isWhitespace)
guard fields.count >= 2, fields[0].hasPrefix("/dev/disk") else { return nil }
@@ -126,26 +127,35 @@ enum VPhonePCCGPURecovery {
?? devices.first?.device
guard let baseDisk, baseDisk.hasPrefix("/dev/disk") else {
if let range = attached.range(of: #"/dev/disk[0-9]+"#, options: .regularExpression) {
- _ = try? run("/usr/bin/hdiutil", ["detach", "-force", String(attached[range])])
+ _ = try? run("/usr/sbin/diskutil", ["unmountDisk", "force", String(attached[range])])
+ if (try? run("/usr/sbin/diskutil", ["eject", String(attached[range])])) != nil {
+ diskMayBeAttached = false
+ }
}
- throw Error.toolFailed("hdiutil", "could not attach the PCC disk image. Try again.")
+ throw Error.toolFailed("diskutil", "could not attach the PCC disk image. Try again.")
}
var mountToClean: URL?
var diskAttached = true
defer {
- if diskAttached, (try? run("/usr/bin/hdiutil", ["detach", baseDisk])) == nil {
- _ = try? run("/usr/bin/hdiutil", ["detach", "-force", baseDisk])
+ if diskAttached {
+ if (try? run("/usr/sbin/diskutil", ["eject", baseDisk])) != nil {
+ diskMayBeAttached = false
+ } else if (try? run("/usr/sbin/diskutil", ["unmountDisk", "force", baseDisk])) != nil,
+ (try? run("/usr/sbin/diskutil", ["eject", baseDisk])) != nil
+ {
+ diskMayBeAttached = false
+ }
}
if let mountToClean {
do {
guard let mounts = fm.mountedVolumeURLs(
includingResourceValuesForKeys: nil, options: [],
) else {
- throw Error.toolFailed("hdiutil", "could not verify detached volumes")
+ throw Error.toolFailed("diskutil", "could not verify detached volumes")
}
let root = mountToClean.resolvingSymlinksInPath().path
guard !mounts.contains(where: { $0.resolvingSymlinksInPath().path == root }) else {
- throw Error.toolFailed("hdiutil", "PCC volume is still mounted")
+ throw Error.toolFailed("diskutil", "PCC volume is still mounted")
}
try fm.removeItem(at: mountToClean)
} catch {
@@ -191,11 +201,13 @@ enum VPhonePCCGPURecovery {
}
mounted = false
do {
- try run("/usr/bin/hdiutil", ["detach", baseDisk])
+ try run("/usr/sbin/diskutil", ["eject", baseDisk])
} catch {
- try run("/usr/bin/hdiutil", ["detach", "-force", baseDisk])
+ try run("/usr/sbin/diskutil", ["unmountDisk", "force", baseDisk])
+ try run("/usr/sbin/diskutil", ["eject", baseDisk])
}
diskAttached = false
+ diskMayBeAttached = false
print("[+] GPU driver staged from cloudOS restored by vphone-cli")
}