Is it possible to read from a device in a kernel module? For example if I wanted to read from /dev/sda how would I go about doing that (I picked /dev/sda just as an example, in my exact scenario I need to read from a character device)? I know user space functions aren't available in kernel modules so I assume the open function for opening a device file is not available, plus I would assume that since the code is already being executed in kernel space there's probably a way to bypass the dev filesystem and access the device directly. Also, if it's not possible to read from it, is it at least possible to check if it exists?
Asked
Active
Viewed 256 times
0
-
Not like this. But in general yes, it’s possible. – 0andriy Oct 23 '21 at 08:40
-
The API has changed over the years, but recent kernel code uses `filp_open`, `filp_close`, `kernel_read` and `kernel_write` functions. Earlier kernels had to muck around switching data segment descriptors with `get_fs` and `set_fs`. – Ian Abbott Oct 25 '21 at 09:27