File I/O in a Linux kernel module

后端 未结 6 1252
闹比i
闹比i 2020-11-30 04:53

I\'m writing a Linux kernel module that needs to open and read files. What\'s the best way to accomplish that?

6条回答
  •  离开以前
    2020-11-30 05:23

    Generally speaking, if you need to read/write files from a kernel module, you're doing something wrong architecturally.

    There exist mechanisms (netlink for example - or just register a character device) to allow a kernel module to talk to a userspace helper process. That userspace helper process can do whatever it wants.

    You could also implement a system call (or such like) to take a file descriptor opened in userspace and read/write it from the kernel.

    This would probably be neater than trying to open files in kernel space.

    There are some other things which already open files from kernel space, you could look at them (the loop driver springs to mind?).

提交回复
热议问题