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.
Related
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.
While we want to create a device file in file system, which one should we choose right now? Make a node in udev, which will show up in /dev or use sysfs which will show up in /sys.
I just think I can accomplish most of functions for a device through these two different ways. So it confused me a lot.
Thanks.
Use udev (and or define and publish some major & minor device numbers, like for mknod). See makedev(3)
Application programs want to access physical devices in /dev/ (not in /sys/). Data to/from a device go usually thru /dev/ char or block devices. Metadata and configuration can go thru sysfs
Read more about udev and about sysfs. See also device file wikipage.
You won't get very useful answers if you don't explain more concretely your issues... What exact kind of device are you thinking about? Very probably there exist already similar devices....
Publish very early (even in alpha stage, when it is not fully working) your device driver and software source code as free software preferably as GPLv2 (the license used by Linux kernel). Ask also on kernelnewbies. Work hard (perhaps more than a year) to get your driver incorporated in the official Linux kernel.
You should be familiar with Advanced Linux Programming (in the application userspace world) before attempting to code a kernel driver. After that, read books and resources on Linux kernel driver programming and study the source code of existing drivers in the recent Linux kernels.
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.
For those familiar with Linux, it is possible to create a module and register it as a block device. This allows the user to mount it as a regular disk (while all the block I/O is handled by the module, e.g. USB mass storage).
Is there a way to do this in Windows ? (Need to create a volume mountable by Windows. The raw data will come from propriety interface).
The easiest way (and it's not easy!) is to write a Storport Miniport driver, you can even do this with KMDF as well. The latest issue of OSR's "The NT Insider" has an article on how to do this, but it's not going to be any kind of easy.
You will learn a ton though, so if you're interested in kernel development, this is a good way to get started!
You can find some simple block device drivers at http://www.acc.umu.se/~bosse/ . Look at the FileDisk driver, which is a Windows equivalent of /dev/loop
Take a look at the Truecrypt project. They have a pretty good implementation of a virtual block device.
I'm not familiar with kernel driver development, so I want to know if there are other easy ways to add a virtual driver like CD Emulation in Windows Explorer.
One approach that might be worth considering is the Dokan project.
From the web site:
By using Dokan library, you can create your own file systems very easily
without writing device driver. Dokan Library is similar to FUSE (Linux user
mode file system) but works on Windows.
The DLL is directly usable from C/C++. There is a .NET binding, and a Ruby binding, both from the "official" project. Samples include a SSHFS, which mounts a remote file system over SSH, a ramdisk, and a mirror among others.
I've seen a whitepaper that demonstrated a file system organized by the tags present in a collection of MP3 files based on the Dokan library. I've also seen an description and demo that mirrored a user's Flickr photo stream in a file system.
I haven't tried it myself, yet, but plan to play with it "soon".
More detail would help a lot on this, but here are some good general suggestions:
If you're trying to mount some kind of virtual filesystem for manipulation within Explorer, a straightforward approach that Just Might Work is that you could expose your filesystem over WebDAV. There are WebDAV libraries for almost any development platform, and all of the major OSes come with the ability to map WebDAV folders for use from within their explorer UI.
Question about your question,
are you looking for a virtual driver that is similar to how explorer handles CD Emulation,
OR
Virtual CD Emulation Driver for windows explorer?