/* ct041012.c - yet another chaostreff announcement * by Clifford Wolf * * echo "obj-m := ct041012.c" > Makefile * make -C /usr/src/linux-2.6.7 SUBDIRS=$PWD modules * insmod ./ct041012.ko */ #include #include #include #include #define N (8*24*60*60+7*60*60) #define M (60*60*24*14) static ssize_t chaos_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) { char text[100], *t; struct timeval tv; int len, secs; do_gettimeofday(&tv); secs = M - (tv.tv_sec + N) % M; len = sprintf(text, "Bis zum naechsten CNGW Chaostreff:\n" "%d Tage, %d Stunden, %d Minuten und %d Sekunden\n", secs/(60*60*24), (secs/(60*60))%24, (secs/60)%60, secs%60); if ( *ppos >= len ) return 0; t = text + *ppos; len -= *ppos; if (len > size) len = size; if ( copy_to_user(buf, text, len) ) return -EFAULT; *ppos += len; return len; } static struct file_operations proc_chaos_ops = { .read = chaos_read }; static int chaos_init() { struct proc_dir_entry *entry; entry = create_proc_entry("chaos", 0, NULL); if (!entry) return -EBUSY; entry->proc_fops = &proc_chaos_ops; return 0; } static void chaos_exit() { remove_proc_entry("chaos", NULL); } module_init(chaos_init); module_exit(chaos_exit); MODULE_AUTHOR("Clifford Wolf "); MODULE_DESCRIPTION("The /proc/chaos driver"); MODULE_LICENSE("GPL");