I’m writing a Linux kernel module, and I’d like to create a subdirectory, /proc/foo/, and then expose several artificial files inside it that will be generated on the fly by my module. I know I can use proc_mkdir to create the foo directory, but if it already exists dmesg will display a warning, and I’d prefer to keep the log clean.
Now you might think on a module teardown it should be removing the /proc/foo/ tree so that a redundant mkdir should never happen. But I’m working on a series of related kernel modules, and I figured I’d have each of them separately expose files in /proc/foo/. Maybe this is atypical? I don’t see any functions in proc_fs.h for querying existing files so maybe I’m going about this wrong?
Another option would be to have a module that just creates the directory, and have it export a global containing the proc_dir_entry, and then all of my modules can extern that variable and use it. But then I have to worry about that module getting loaded before all of the others. But maybe that’s the way this is usually done? I’m interested in knowing what best practices are.
Advertisement
Answer
It is odd. If you really want everything grouped just create a module providing /proc/foo and make everything else depend on it.