I am trying to open a shm file for data sharing between kernel and user process. Below is my kernel module code. Sys log output indicates that no errors were encountered. Once the module is loaded, I don't see the file that I'm trying to create in /dev/shm. What am I doing wrong?
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/shmem_fs.h>
static int __init moduleLoader(void) {
struct file *shfile;
printk(KERN_INFO "shkmod is loading...\n");
shfile = shmem_file_setup("MyShmFile",sizeof(int),0);
printk("shmem_file_setup returned %p\n",shfile);
if (IS_ERR(shfile))
printk("shmem_file_setup returned error.\n");
printk("shfile is: %s\n", shfile->f_path.dentry->d_name.name);
printk(KERN_INFO "shkmod is done loading.\n");
return 0;
}
static void __exit moduleUnloader(void) {
printk(KERN_INFO "shkmod was unloaded.\n");
return;
}
module_init(moduleLoader);
module_exit(moduleUnloader);
MODULE_AUTHOR("Yaron Shragai");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Lorem ipsum dolor sit amet");
Here is the output in the sys log:
Jun 6 15:25:59 yaron-VirtualBox kernel: [457160.335482] shkmod is loading...
Jun 6 15:25:59 yaron-VirtualBox kernel: [457160.335487] shmem_file_setup returned ffff8801fef53b00
Jun 6 15:25:59 yaron-VirtualBox kernel: [457160.335488] shfile is: MyShmFile
Jun 6 15:25:59 yaron-VirtualBox kernel: [457160.335488] shkmod is done loading.
$ uname -a
Linux yaron-VirtualBox 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux