Det (officielle?) fklub kernel modul. Originalt lavet af jokke, mchro & kyrke 2006.
#include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> #define MAX_Fs 99999 //-1 for infinitet /* Bør denne ikke være unsigned, ellers er der ikke flere f'er, når den wrapper? -mchro (17-02-08) */ int fCount = 0; static int device_open(struct inode *i, struct file *f) { return 0; } static int device_close(struct inode *i, struct file *f) { return 0; } static ssize_t device_read( struct file *f, char *buffer, size_t length, loff_t *offset) { *buffer = 'F'; fCount++; if (fCount != -1 && fCount >= MAX_Fs){ panic("No more F's"); } return 1; } static ssize_t device_write( struct file *f, const char *buffer, size_t length, loff_t *offset) { if (*buffer = 'F' || *buffer = 'f'){ fCount--; }else{ panic("My world only contains F!!! ") } return length; } static struct file_operations fops = { .read = device_read, .write = device_write, .open = device_open, .release = device_close }; static int major; static int device_init(void) { major = register_chrdev(0, "null device", &fops); if (major < 0) { printk("Init failed (%d)\n", major); return major; } printk("Got major %d\n", major); return 0; } static void device_exit(void) { int n = unregister_chrdev(major, "null device"); if (n < 0) { printk("Cleanup failed (%d)\n", n); } } module_init(device_init); module_exit(device_exit); MODULE_LICENSE("GPL");