I'd like save a kext setting between OS restarts. As I need the settings after kext been loaded immediately, I can not wait for managing daemon start up. Is it a way for reading/writing kext plist file from kext or some other ways to do that?
1 Answers
Basically, no - you're supposed to store settings in userspace and use a launchd service to set them in the kext. Until your kext receives the settings, it should just use some sane defaults.
One way to truly include settings on kext startup is to add custom attributes to the IOKitPersonality in your kext's info.plist. Obviously, this means that changing settings requires changing the kext itself, but I have heard reports of people actually doing this on Apple's public darwin mailing lists (although Apple employees pitched in to criticise it). Note that the kext cache will not like this: If your userspace program changes settings in the info.plist, it will probably need to increase the bundle version number in order for the kext cache to pick up the change, otherwise the cached/prelinked kext won't see the change. You need to do this within the constraints of the rules for kext bundle versions or it won't be detected as a version increase, or worse, the kext cache will reject the kext outright. Also, don't forget to touch /System/Library/Extensions/ after updating kexts.
Update: modifying a kext's info.plist will no longer work in 10.9 and 10.10 due to the kext signing requirement.
In the specific case where your kext is a storage filter scheme, you can store your settings in a special "super block" of the provider partition. AppleRAID (which is open source) does this, for example. This isn't practical for any other kind of kext, though.

- 22,018
- 3
- 52
- 103
-
Hi, I'm dealing with the same situation and I didn't understood how to use the `launchd` to set the modified plist in the kext. perhaps you can elaborate on this ? thanks – Zohar81 Nov 07 '17 at 12:04
-
@Zohar81 There are many ways of doing this, but for example if your driver is IOKit based, you can create a daemon which matches your driver's `IOService` class. When the daemon starts, connect to the driver's service, either by setting properties or by opening a user client. Then, configure away. – pmdj Nov 07 '17 at 14:45
-
I'm actually working on IOKit base drive, and doing the matching and connecting parts, but I'm looking for a generic way to set my driver properties (assuming that the configuration length and type may vary). perhaps you can relate to an add-hoc question I've published (https://stackoverflow.com/questions/47160052/passing-cfdictionary-via-iokit-command) – Zohar81 Nov 07 '17 at 14:49