0

How do you mount a loop device (similar to hdiutil attach) on XNU / Darwin in C?

Specifically I'm looking for functionality that would be in linux/loop.h, but on XNU. ( I'm going to be doing this on iOS, don't ask ;) )

pmdj
  • 22,018
  • 3
  • 52
  • 103
spv
  • 46
  • 1

1 Answers1

1

There is no public API for disk images in macOS/Darwin. The disk image mechanism used by hdiutil is not implemented in core XNU itself, but the kext /System/Library/Extensions/IOHDIXController.kext. I have seen no documentation or source code on it, and I am not aware of a user space library for interfacing with it which is a public API. You will likely need to shell out to hdiutil on macOS.

Whether there's any chance of doing this on iOS is another question. (I assume you are talking about a jailbroken system) Judging by how OTA updates work in iOS, I can't think of anything else for which the OS itself might use disk images. So it seems likely that iOS has no disk image support at all. You could see what happens if you load an .iso or .dmg onto a USB storage device, connect that to your iDevice and try to open it in Files.app, but I'm not especially optimistic you'll be able to open them.

pmdj
  • 22,018
  • 3
  • 52
  • 103
  • Yes, it is for a jailbroken device. I will check for IOHDIXController.kext, and I have also heard there is a PrivateFramework for doing it. – spv Jun 03 '20 at 17:17
  • Sadly, the kext doesn't exist. – spv Jun 03 '20 at 17:21
  • @spv Judging by [this page on how OTA updates work on iOS](https://www.theiphonewiki.com/wiki/OTA_Updates#:~:text=OTA%20Updates%20(Over-the-,without%20the%20need%20for%20iTunes.)) it doesn't look like iOS uses disk images at all, so I would not be surprised if that functionality was entirely missing from the OS. Best way to check is probably to try to open an .iso or .dmg from Files.app. – pmdj Jun 04 '20 at 08:32
  • I figured out that comex has a utility written in C I could use, and since I couldn't compile it, I decided to just use the pre-compiled version from SuccessionRestore. https://github.com/Samgisaninja/SuccessionRestore – spv Jun 06 '20 at 15:42