File Access In Kernel Modules?
gibson_81 asks: "I'm writing a device driver for a really ugly piece of hardware: it needs me to read in firmware from a file before I can initialize it. For now, I force the user-program to read the entire file into memory and pass that memory buffer as an IOCTL argument, but that's even uglier than the hardware. None of the documents on writing kernel device drivers have mentioned how to access files from the kernel, but some source-grepping led me to sys_open ... which was not exported to modules :( So, I ask you, the Slashdot community: do you know what functions I can use to do this, or is it a no-no?"
Compiling the firmware into the module may not be allowed, depending on the copyright on the firmware (you're making a derivative work of the firmware, which may be restricted by the firmware's license); in any case, this approach would make it illegal to compile the driver into the kernel (as, presumably, the firmware's license is not GPL-compatible).
I don't see the problem, though, with the IOCTL approach. Why not have a function that loads the firmware from memory? It seems like a flexible approach. To load the firmware from a file it's basically two calls, an mmap to make the file look like memory, and then the ioctl to load it. Why go through the pain of making the kernel do file I/O?
The ioctl approach is more hacker-friendly, as it allows users to experiment with different firmware more easily.