#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 ) { char* readspot = text + *offp; size_t readlen = strlen(readspot) > count? count:strlen(readspot); printk("proc_read just ran! count = %lu, sizeof(loff_t) = %lu, *offp = %llu\n", count, sizeof(loff_t), *offp); if(*offp >= strlen(text)) return 0; strncpy(buf, readspot, count); *offp += readlen; return readlen; } ssize_t write_simple(struct file *filp,const char *buf,size_t count,loff_t *offp) { return 0; } struct proc_ops proc_fops = { proc_read: read_simple, proc_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);