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 ;) )
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.
Related
I had developed a kernel extension(kext) by IOKit, but it will be deprecated in the future. So I want develope another driver use dext to replace kext using the DriverKit. But I don't find the executable solutions, like that I cannot find the some class to repalce IOMedia. When I intend to include IOKit in my code,I found the TARGET_OS_DRIVERKIT is 1.
Can someone help me? Thanks a lot!
IOMedia is a subclass of IOStorage and part of the IOStorageFamily. As of the macOS 11.2 SDK (Xcode 12.4) this has not yet been ported to DriverKit.
The SCSIControllerDriverKit API has been in beta since WWDC 2020. It didn't ship with the release versions of macOS 11.0.x-11.2. It's included in the (as of this writing) current betas of 11.3. Perhaps it will see general release with macOS 11.3. This is not a direct port of the storage stack; instead, it's essentially a port of the IOParallelSCSIController KPI. This lets you implement a driver for, well, a SCSI controller. Such a driver can tell the OS about one or more SCSI devices, including block devices, and will start receiving SCSI commands from the system, which it is expected to forward to the underlying controller device. It does not allow you to implement "filter" storage drivers, or to issue SCSI commands to other devices in the system.
I would like to know whether SoX/LibSoX offers the possibility to access a sound device in exclusive/hog mode. The idea is to prevent other applications from accessing the sound card / DAC that is being used by the focal app.
My main target is OSX CoreAudio output, but I am also eager to know about Linux (OSS/Alsa).
I know this is possible in CoreAudio, because I have seen it implemented in several apps, including this open source one.
On Mac OS X at least, the answer appears to be no. In http://sourceforge.net/p/sox/code/ci/master/tree/src/coreaudio.c SoX uses the default input or output device but there is no provision for hog mode.
I want to create a fake flash drive programmatically under Mac OSX and Windows.
It should behave like a normal drive, that means it should appear in explorer/finder, should be unmountable,.. If someone puts some data in it, it should be handled in a backend software.
Is that possible?
I'm not aware of any existing cross-platform frameworks. For Windows, the documentation for writing device drivers is here: http://msdn.microsoft.com/en-us/library/ff557573. See also http://msdn.microsoft.com/en-us/windows/hardware/gg463062 but note that this is hard-core stuff.
I have one USB stick having FAT32 type file system.I really in need to dump and analyze that file system in the usb stick in windows or in linux platform.
My ultimate aim is to read the usb's hardware( ,type and manufacturer) information by reading that dump file.
You will not find the information you are looking for in the file system, those are embedded in the chip and are transmitted when the device gets plugged in. You will find all details in the device manager if you look up the details of the device.
Regarding your comment: It is irrelevant for the OS what the actual filesystem is, as the controller on the device controls the access to the actual flash memory. If the controller says that there are only 400mb to be accessed, you can only access 400mb. You either got a faulty stick or it's a fraud, you probably should check with the origin of it (ie. where you bought it). Sometimes, you can flash the device's firmware, for that the information you get in the device manager is enough. However, at most times, you are out of luck - return the stick if you can in that case.
there seem to be more and more questions that are answered by "why do you want to do that" instead of real information. Strange.
Here is an answer:
Don't use Windows. Use Linux, plug in the stick, and use 'dd' to dump partitions from the stick to files.
Cheers.
How does one go about creating a virtual CD driver on Mac OS X programatically?
I can't find any relevant Cocoa APIs or any pure C BSD solutions.
Any help or information is appreciated.
You would need to use the I/O Kit framework to develop your own device driver that would emulate a virtual CD drive. Here are some links to the relevant APIs to get you started.
I/O Kit Fundamentals
I/O Kit Device Driver Guidelines
Kernel Extension Programming Topics
There are several different answers people have proposed here. The issue at hand is what are you trying to accomplish. If you really want to emulate a CD ROM (down to the commandset) you will need to write a device driver. If your goal is merely to emulate a block device with contents similiar to a CD you can create a disk image using disk utility and let the builtin disk image driver handle it for you.
MacFUSE is useful if you want to present some sort of custom filesystem functionality, but if what you are looking for is something that has the same semantics as an optical disc (whether that is and block or command set level) it is the wrong tool.
If you're simply looking to mount an ISO or something then it's done through the Disk Utility, simply drag it into the side-bar and then select it and choose mount.
If you want to do it from code you can issue the hdiutil command, as shown here. I'm not sure if there's an API call to do it, but getting that command to do the work is quite painless.
The simplest way to mount a custom volume is MacFUSE. It handles the IOKit details for you and lets you write the implementation in user space. However, I don’t think you can make a MacFUSE “look like” a CD; you’d have to modify FUSE to achieve that.
I had a nosey around DAEMON Tools for Mac's driver:
/Library/Extensions/DAEMONToolsVirtualSCSIBus.kext/Contents/MacOS/DAEMONToolsVirtualSCSIBus
I disassembled the binary using Hopper and discovered they are using
IOSCSIProtocolServices.