Is there any way to open a file inside kext

I'm writing a kext and

My requirement is to load the configuration during the runtime, when it is triggered from userspace or within the kext


Is it possible to open a file inside kext and perform read operation inside kext,

or can you suggest any alternatives for this!!


Thanks

Venkat

Accepted Reply

You can do this using various vnode KPIs. Start with

vnode_open
in
<sys/vnode.h>
in the Kernel framework.

However, there are some things to consider here:

  • We generally recommend that kernel code not read configuration files directly. Rather, it should start with a default configuration and then allow for dynamic reconfiguration based from a daemon as the system boots.

  • For large read-only files, like firmware images, you can load the file using OSKextRequestResource (

    <libkern/OSKextLib.h>
    ).
  • If your KEXT is on the boot path — and Ethernet drivers can be on the boot path when the system is configured to netboot — you have to avoid deadlocking. In that case you want to get your configuration from NVRAM, using

    IODTNVRAM
    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

You can do this using various vnode KPIs. Start with

vnode_open
in
<sys/vnode.h>
in the Kernel framework.

However, there are some things to consider here:

  • We generally recommend that kernel code not read configuration files directly. Rather, it should start with a default configuration and then allow for dynamic reconfiguration based from a daemon as the system boots.

  • For large read-only files, like firmware images, you can load the file using OSKextRequestResource (

    <libkern/OSKextLib.h>
    ).
  • If your KEXT is on the boot path — and Ethernet drivers can be on the boot path when the system is configured to netboot — you have to avoid deadlocking. In that case you want to get your configuration from NVRAM, using

    IODTNVRAM
    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"