#include #include #include #include #include #include #include #include #define PROC_FILE_NAME "remember_file" #define BUFSIZE (1024*1024) unsigned char *buffer; size_t buffer_contents = 0; ssize_t read_simple(struct file *filp,char *buf,size_t count,loff_t *offp ) { size_t copysize = count; size_t potential_copy = buffer_contents - *offp; printk("READ: buf = %lx, count = %lu, *loff_t = %llu\n", (long unsigned int)buf, count, *offp); if(*offp >= buffer_contents) return 0; if(potential_copy < count) copysize = potential_copy; memcpy(buf, buffer + *offp, copysize); *offp += copysize; return copysize; } unsigned int call_count = 0; ssize_t write_simple(struct file *filp,const char *buf,size_t count,loff_t *offp) { size_t copysize = count; printk("WRITE: content = %s\n, buf = %lx, count = %lu, *loff_t = %llu\n", buf, (long unsigned int)buf, count, *offp); if(count + buffer_contents > BUFSIZE) copysize = BUFSIZE - buffer_contents; memcpy(buffer + buffer_contents, buf, copysize); *offp += copysize; buffer_contents += copysize; return copysize; } struct file_operations proc_fops = { read: read_simple, write: write_simple }; int proc_init (void) { printk("We're in the kernel!\n"); buffer = kmalloc(BUFSIZE, GFP_KERNEL); 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);