admin管理员组文章数量:1302384
I am wondering if it is possible to write a Linux module along the following lines:
fops_impl.h
- Declare the function prototypes of various functions that can be used to initialize members of struct file_operations
fops_impl.c
- Define the various methods that are used to initialize members of struct file_operations
foo_module.c
- #include fops_impl.h
- Define and initialize static instance of struct file_operations
- Use the symbol of struct file_operations to create and register a char device
This code base builds a module i.e. one can load the module as determined by lsmod. However there is no char device and neither are printk statements in the kernel log.
Questions:
- Is it necessary for struct file_operations to be static?
- Is there a working example of a char device where:
- Device registration is one file
- Its file operations is defined in yet another file
I am wondering if it is possible to write a Linux module along the following lines:
fops_impl.h
- Declare the function prototypes of various functions that can be used to initialize members of struct file_operations
fops_impl.c
- Define the various methods that are used to initialize members of struct file_operations
foo_module.c
- #include fops_impl.h
- Define and initialize static instance of struct file_operations
- Use the symbol of struct file_operations to create and register a char device
This code base builds a module i.e. one can load the module as determined by lsmod. However there is no char device and neither are printk statements in the kernel log.
Questions:
- Is it necessary for struct file_operations to be static?
- Is there a working example of a char device where:
- Device registration is one file
- Its file operations is defined in yet another file
- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Feb 13 at 23:53
1 Answer
Reset to default 0I was able to build a "hello world" module with following properties:
file_module.c: Implements the following
- module_init
- Calls method to register char device
- module_exit
- Calls methods to deregister char device
file_chardev.c: Implements the following
- extern struct file_operations
- Method to register a char device
- Method to deregister a char device
file_fops_impl.h: Implements the following
- Declares prototypes of methods used to initialize members of struct file_operations
file_fops.c: Implements the following
- include header file: file_fops_impl.h
- struct file_operation fops = { - - - }
file_fops_impl.c: Implements the following
- include header file: file_fops_impl.h
- Methods that are used to initialize members of struct file_operations
My earlier question became moot when I tried again the same code after a reboot. What is strange is the call to module_init() didn't print any kernel log messages even though I had print statement with error mode.
本文标签: file ioCan someone use nonstatic instance of struct fileoperationsStack Overflow
版权声明:本文标题:file io - Can someone use non-static instance of struct file_operations - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741695359a2392972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论