#include #include #include #define procfs_name "helloworld" struct proc_dir_entry* Our_Proc_File; struct proc_dir_entry proc_root; int procfile_read(char* buf, char** buf_loc, off_t off, int buf_len, int* eof, void* data) { int ret; printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name); if (off > 0) ret = 0; else ret = sprintf(buf, "HelloWorld!\n"); return ret; } int init_module(void) { Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL); if (Our_Proc_File == NULL) { remove_proc_entry(procfs_name, NULL); //remove_proc_entry(procfs_name, &proc_root); printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", procfs_name); return -ENOMEM; } Our_Proc_File->read_proc = procfile_read; Our_Proc_File->mode = S_IFREG | S_IRUGO; Our_Proc_File->uid = 0; Our_Proc_File->gid = 0; Our_Proc_File->size = 37; printk(KERN_INFO "/proc/%s created\n", procfs_name); return 0; } void cleanup_module(void) { remove_proc_entry(procfs_name, NULL); //remove_proc_entry(procfs_name, &proc_root); printk(KERN_INFO "/proc/%s removed\n", procfs_name); }