You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

176 lines
3.7 KiB

/*
* A /dev/pony device driver. You can't live without it!
* Rhaamo <rhaamo@sigpipe.me>
*/
/* I've put a beautifull unicode ♥ at the end too, if it mess something, remove them and try again.
* Or you can buy a Real Linux©® Operating System with a Gore C Compiler which understand unicode.
*/
/* Include random stuff here */
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <asm/uaccess.h>
#include <linux/random.h>
/* And the most important, the ponies */
#include "pony.h" // <- here are derplicious ponies
/*
* pony_read is the function called when a process calls read() on
* /dev/pony. It writes a pony to the buffer passed in the
* read() call.
*/
static ssize_t
pony_read(struct file * file, char * buf, size_t count, loff_t *ppos) {
/*
* If file position is non-zero, then assume the string has
* been read and indicate there is no more data to be read.
*/
if (*ppos != 0)
return 0;
/* Here we will be run only one time */
/* EWWWW EWWWW EWWWWW
* GRUIIIIII GRUIIII
* EWWWWWW
* Please don't look at this UGLY SHIT
*/
unsigned int i;
(void)get_random_bytes(&i, sizeof(int));
i = i % 11;
char *poni;
//printk(KERN_INFO "Pony: %i\n", i);
switch (i) {
case 1:
poni = some_pony_1;
//printk(KERN_INFO "Pony: 1\n");
break;
case 2:
poni = some_pony_2;
//printk(KERN_INFO "Pony: 2\n");
break;
case 3:
poni = some_pony_3;
//printk(KERN_INFO "Pony: 3\n");
break;
case 4:
poni = some_pony_4;
//printk(KERN_INFO "Pony: 4\n");
break;
case 5:
poni = some_pony_5;
//printk(KERN_INFO "Pony: 5\n");
break;
case 6:
poni = some_pony_6;
//printk(KERN_INFO "Pony: 6\n");
break;
case 7:
poni = some_pony_7;
//printk(KERN_INFO "Pony: 7\n");
break;
case 8:
poni = some_pony_8;
//printk(KERN_INFO "Pony: 8\n");
break;
case 9:
poni = some_pony_9;
//printk(KERN_INFO "Pony: 9\n");
break;
case 10:
poni = some_pony_10;
//printk(KERN_INFO "Pony: 10\n");
break;
case 11:
poni = some_pony_11;
//printk(KERN_INFO "Pony: 11\n");
break;
default:
poni = some_pony_1;
//printk(KERN_INFO "Pony: defaut 1");
break;
}
int len = strlen(poni); /* Don't include the null byte. */
/*
* Besides copying the string to the user provided buffer,
* this function also checks that the user has permission to
* write to the buffer, that it is mapped, etc.
*/
if (copy_to_user(buf, poni, len))
return -EINVAL;
/*
* Tell the user how much data we wrote.
*/
*ppos = len;
return len;
}
/*
* The only file operation we care about is read.
*/
static const struct file_operations pony_fops = {
.owner = THIS_MODULE,
.read = pony_read,
};
static struct miscdevice pony_dev = {
/*
* We don't care what minor number we end up with, so tell the
* kernel to just pick one.
*/
MISC_DYNAMIC_MINOR,
/*
* Name ourselves /dev/pony.
*/
"pony",
/*
* What functions to call when a program performs file
* operations on the device.
*/
&pony_fops
};
static int __init
pony_init(void) {
int ret;
/*
* Create the "pony" device in the /sys/class/misc directory.
* Udev will automatically create the /dev/pony device using
* the default rules.
*/
ret = misc_register(&pony_dev);
if (ret)
printk(KERN_ERR
"Unable to register \"pony\" misc device\n");
return ret;
}
module_init(pony_init);
static void __exit
pony_exit(void) {
misc_deregister(&pony_dev);
}
module_exit(pony_exit);
/* Here some stuff that's usefull */
MODULE_LICENSE("WTFPL"); /* Troll */
MODULE_AUTHOR("Rhaamo <rhaamo@sigpipe.me>"); /* hey look mom it's me ! */
MODULE_DESCRIPTION("pony module"); /* bla bla bla this module is doing useless stuff bla bla bla <insert buzzwords here, and fuck yeaaa for 80 cols, ♥ */
MODULE_VERSION("dev"); /* wtflol */