#include #include #include #include #include #include #include #include #include #define PROC_FILE_NAME "cat_trap" #define CAT_TRAP_DISABLED 0 #define CAT_TRAP_ANIMATED 1 #define CAT_TRAP_KERNEL 2 char status = CAT_TRAP_DISABLED; char animation_chars[] = "-\\|/-\\|/"; int a_place = 0; char a_backspace = 0; ssize_t read_simple(struct file *filp, char *buf, size_t count, loff_t *offp ) { ssize_t ctu_result; if(status == CAT_TRAP_DISABLED) return 0; while(status == CAT_TRAP_KERNEL) ssleep(1); if(a_backspace){ ctu_result = copy_to_user(buf, "\b", 1); a_backspace = 0; } else { ctu_result = copy_to_user(buf, animation_chars + a_place, 1); a_place++; if(a_place > 8) a_place = 0; a_backspace = 1; msleep(100); } return 1; } ssize_t write_simple(struct file *filp,const char *buf,size_t count,loff_t *offp) { printk("Received command: %s", buf); if(!strncmp(buf, "enable_a", 8)) status = CAT_TRAP_ANIMATED; if(!strncmp(buf, "enable_k", 8)) status = CAT_TRAP_KERNEL; if(!strncmp(buf, "disable", 7)) status = CAT_TRAP_DISABLED; return count; } struct proc_ops proc_fops = { proc_read: read_simple, proc_write: write_simple }; int proc_init (void) { printk("We're in the kernel!\n"); // Second argument is a umode_t that is the file permissions // 0 give the default, not an actual 0 proc_create(PROC_FILE_NAME,0666,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);