#include #include #include #include #include #include #include #include #define PROC_FILE_NAME "testfile" char text[] = "There was an armadillo which had a lot of money to invest. Gold, stocks, property, and bitcoin were all too high!"; ssize_t read_simple(struct file *filp, char *buf, size_t count, loff_t *offp ) { size_t textlen = strlen(text) - *offp; size_t readlen = textlen < count? textlen : count; memcpy(buf, text + *offp, readlen); *offp += readlen; printk("Read called with buffer size: %lu\n", count); return readlen; } ssize_t write_simple(struct file *filp,const char *buf,size_t count,loff_t *offp) { printk("Write was called, with a buffer containing %s\n", buf); return count; } struct file_operations proc_fops = { read: read_simple, write: write_simple }; int proc_init (void) { printk("We're in the kernel!\n"); proc_create(PROC_FILE_NAME,0,NULL,&proc_fops); return 0; } void proc_cleanup(void) { remove_proc_entry(PROC_FILE_NAME,NULL); } MODULE_LICENSE("GPL"); module_init(proc_init); module_exit(proc_cleanup);