You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:macOS10.15+下用DriverKit开发磁盘读取dext替代kext遇阻

Migrating Disk Reading from KEXT (IOKit) to DriverKit DEXT

Hey there, let's work through how to port your disk-reading functionality from a traditional IOKit KEXT to a DriverKit system extension (DEXT) — I’ve navigated this transition before, so here’s a clear breakdown of what you need to know:

Key Differences & Replacement for IOMedia

First off, DriverKit doesn’t have a direct 1:1 replacement for IOMedia — instead, you’ll work with the IOStorageDriverKit framework, which is DriverKit’s dedicated suite for storage device interactions. Here’s how to map your old IOMedia-based logic:

  • Instead of interacting with IOMedia objects, you’ll use IOStorageDevice to represent the underlying storage device. This class gives you access to critical device properties like block size, total block count, and device identifiers.
  • Your core driver logic will live in a subclass of IOStorageDriver — this is where you’ll handle device initialization, read/write operations, and cleanup.

Understanding TARGET_OS_DRIVERKIT=1

That macro being set to 1 is totally expected when working in a DriverKit project! DriverKit is a sandboxed, user-space replacement for kernel extensions, so it intentionally blocks access to many legacy IOKit kernel APIs. You can’t import traditional IOKit headers and use kernel-side classes like IOMedia in a DEXT — you have to fully embrace DriverKit’s own frameworks (IOStorageDriverKit, IOKitDriverKit) instead.

Step-by-Step Implementation Tips

  • Start with the right template: In Xcode, create a new project using the "DriverKit System Extension" template. This sets up the correct build settings, entitlements, and framework imports automatically.
  • Hook into storage device events: Override the Start method in your IOStorageDriver subclass to initialize the IOStorageDevice instance and register for device notifications.
  • Implement block reading: Use the ReadBlocks method (provided by IOStorageDriver) to handle read requests. Unlike KEXTs, DriverKit uses an asynchronous model — you’ll pass an IOKitCompletion callback to handle the result of the read operation once it’s done.
  • Configure entitlements: Your DEXT needs the com.apple.security.device.storage entitlement in its Info.plist to access storage devices. Don’t forget to sign and notarize your extension for distribution (or testing locally with a developer ID).

Testing & Debugging

  • Use ioreg -l to verify that your DEXT is loaded and attached to the target storage device. Look for your driver’s class name in the output.
  • For testing read operations, you can write a simple user-space helper app that communicates with your DEXT via XPC (DriverKit extensions use XPC to interact with user-space processes).
  • Check the system log (Console app, filtering for your driver’s name) for any error messages or debug logs you’ve added.

内容的提问来源于stack exchange,提问作者Dirk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 09:12:33