简体   繁体   中英

configuration file for kernel module

I learn how to write linux kernel drivers and now I would like to give user from userspace possibility to change behaviour of my modules (or any other subsystem / module).

I would like to store any value (string list) in any type of configuration file / system and in form of the value inside file / system - change the behavior of modules.

I thought about procfs , I can make module which creates /proc/file and react to read/write operations from userspace.

The thing is: how to read that configuration from another, name it B, module in kernel space?

Maybe another type of config is possible (I thought about sysctl but I see there is no strings stored and I have to store some kind of simple "list").

1) Usually, if it is configuration and some of parameter list, ioctl is more popular and recommend to use it.

2) You are asking, There are 2 kernel modules - A and B and you want to read A's configuration on B. Right? In this case, no matter what you have proc or ioctl (remember, proc is not real file-system. You are printing or reading and returning some value from some kernel variables... you can read contents from "fs" by using VFS in kernel and return the string but that is very very stupid since you have user space control.), eventually, you need to store your kernel module config to some variables. If you want to read them from another module, your variable should be exposed by using EXPORT_SYMBOL() keyword, but usually, we don't do.

Create some API on your symbol which is returning the config value and expose those APIs and call it from another module. Because of module dependency, you may need to be careful.

The easiest way to do it is, to create some callback ptr and define it under kernel source code. And then, when module A is initialized, configure callback ptr, and call it from module B. In this case, you will get rid of module dependency.

or, create callback pointer on module B and make module B as built-in module and expose callback ptr.

Then, from module A, you can initialize those and whenever you call it from B, you can check "null ptr" on that callback ptr.

Hope that it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM