简体   繁体   English

IOKit驱动程序,用于创建/注册虚拟存储设备

[英]IOKit Driver to create/register virtual storage device

I am currently learning how to write os x kernel extensions (in Xcode) so sorry If I have any facts wrong. 我目前正在学习如何在Xcode中编写os x内核扩展,所以抱歉,如果我有任何错误的事实。 I am looking for an example of how I can write a IOKit Driver that can register a virtual storage device in the system (like a usb hard drive, usb stick or SD card etc..) that would show up as a normal device drive in finder, I believe it would be around the IOMedia area and use class IOBlockStorageDevice but Im not completely sure. 我正在寻找一个示例,说明如何编写IOKit驱动程序,该驱动程序可以在系统中注册虚拟存储设备(例如USB硬盘驱动器,USB记忆棒或SD卡等)。查找程序,我相信它会在IOMedia区域周围并使用IOBlockStorageDevice类,但我不确定。 I want the kernel to be able to handle all the functions like read and write actions, mounting and ejecting, etc... 我希望内核能够处理所有功能,例如读取和写入操作,安装和弹出等。

In the very end I wanna create device driver to detect an android device (which uses MTP) and mount it as a storage device allowing users to read and write to it in finder and the driver will handle the read and write sending the data to the phone. 最后,我想创建设备驱动程序以检测android设备(使用MTP)并将其安装为存储设备,以允许用户在finder中对其进行读写,而该驱动程序将处理将数据发送到硬盘的读写操作。电话。 (I know theres likely other drivers out there that do this but I would like to make my own) But for now I just wanna know how to make a driver that can generate a virtual usb drive. (我知道那里可能还有其他驱动程序可以执行此操作,但是我想自己做)。但是现在,我只想知道如何制作可以生成虚拟USB驱动器的驱动程序。

Thankyou for putting up with me 谢谢你支持我

For example code of a virtual disk, the "Ramdisk" project from Chapter 14 of the example code from the book 'OS X and iOS Kernel Programming' by Ole Henry Halvorsen and Douglas Clarke is a reasonable starting point. 例如,关于虚拟磁盘的代码,由Ole Henry Halvorsen和Douglas Clarke 撰写的 “ OS X和iOS内核编程” 一书示例代码的第14章中的“ Ramdisk”项目是一个合理的起点。

Instances of the IOMedia class are normally created automatically by the storage subsystem; IOMedia类的实例通常由存储子系统自动创建。 you don't normally need to subclass it. 您通常不需要继承它。 Subclassing IOBlockStorageDevice is usually the way to go for block storage device drivers, whether they're virtual or physical. 子类化IOBlockStorageDevice通常是块存储设备驱动程序的方式,无论它们是虚拟的还是物理的。 (For example, macOS's disk image (dmg) handling is implemented in IODiskImageBlockStorageDeviceOutKernel , also a subclass of IOBlockStorageDevice , while the USB mass storage driver is based on SCSI, so the IOSCSIPeripheralDeviceType00 creates an IOBlockStorageServices which is in turn a subclass of IOBlockStorageDevice ) (例如,MACOS的磁盘映像(DMG)处理在实施IODiskImageBlockStorageDeviceOutKernel ,也是一个子类IOBlockStorageDevice ,而USB大容量存储驱动程序基于SCSI,所以IOSCSIPeripheralDeviceType00创建IOBlockStorageServices其依次的子类IOBlockStorageDevice

I should point out however, that for your ultimate goal, a block storage device is probably not a good solution. 但是,我要指出,对于您的最终目标,块存储设备可能不是一个好的解决方案。 MTP is as far as I'm aware file based, and does not represent a block device. 据我所知,MTP是基于文件的,并不代表块设备。 So for applications to see the files on the block device, you'd need to emulate some kind of file system backend inside your virtual block device driver, which is going to be unnecessarily complicated even if you pick something simple like FAT. 因此,要使应用程序查看块设备上的文件,您需要在虚拟块设备驱动程序内模拟某种文件系统后端,即使您选择了FAT之类的东西,也会变得不必要地复杂。

It's probably a better approach to implement this as a file system driver. 将其实现为文件系统驱动程序可能是更好的方法。 FUSE would probably be a good starting point for this; 保险丝可能是一个很好的起点。 if you find that overly limiting, you can always turn it into a "true" kernel based VFS kext. 如果发现过度限制,则始终可以将其转换为基于“真正”内核的VFS kext。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM