#include #include #include #include #include #include static int major; static char *name = "foo"; static volatile int count = 0; int foo_open(struct inode* inode, struct file *filp) { return 0; } ssize_t foo_read(struct file *filp, char *buf, size_t n, loff_t *offp) { //if (count < 10000000) printk("count = -1\n"); printk("count = %u\n", count); count = 0; return 0; } ssize_t foo_write(struct file *filp, const char *buf, size_t n, loff_t *offp) { volatile int tmp; int i; for(i = 0; i < 10000; i++) { tmp = count; tmp++; count = tmp; } return n; } struct file_operations fops = { .open = foo_open, .read = foo_read, .write = foo_write }; static int hello_init(void) { count = 0; printk("loading..count = %u\n", count); major = register_chrdev(0,name, &fops); printk("got major = %d\n", major); if (major < 0) return major; return 0; } static void hello_exit(void) { unregister_chrdev(major, name); printk("Hello cleaning up...\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL");