Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/ioport.h> /* request_region, check_region, release_region */
- #include <linux/init.h> /* Needed for the macros */
- #define MAGICNUM 0x14000000
- #define CRIME_MAJOR_NUM 300
- static int crime_open(struct inode*, struct file*);
- static int crime_close(struct inode*, struct file*);
- static ssize_t crime_write(struct file*, const char __user*, size_t, loff_t*);
- static ssize_t crime_read(struct file*, char*, size_t, loff_t*);
- static int crime_ioctl(struct inode*, struct file*, unsigned int, unsigned long);
- struct file_operations crime_fops = {
- .owner = THIS_MODULE,
- .open = crime_open,
- .release = crime_close,
- .read = crime_read,
- .write = crime_write,
- .ioctl = crime_ioctl
- };
- int port;
- static int __init crime_init(void) {
- int result;
- pr_debug("crime_init called\n");
- if ((result = register_chrdev(CRIME_MAJOR_NUM, "crime", &crime_fops)) < 0)
- printk(KERN_ERR, "register_chrdev %d\n", result);
- return result;
- }
- static void __exit crime_exit(void) {
- printk("crime_exit called, unloading module\n");
- }
- static ssize_t
- crime_read(struct file* flip, char* ubuf, size_t count, loff_t* f_pos) {
- ssize_t len, ret;
- const char* works = "It works!\n";
- len = min(count, strlen(works));
- if (copy_to_usr(ubuf, works, len)) {
- ret = -EFAULT;
- goto free_page;
- }
- *f_pos += len;
- ret = len;
- free_page:
- return ret;
- }
- static int crime_open(struct inode* inode, struct file* flip) {
- return 0;
- }
- static int crime_close(struct inode* inode, struct file* flip) {
- return 0;
- }
- static ssize_t
- crime_write(struct file* flip, const char* __user ubuf, size_t count, loff_t* f_pos) {
- /* per stampare in debug ubuf bisognerebbe copiarlo prima o quantomeno
- fare dei controlli se si tratta di dati grezzi etc */
- printk("crime_write was called with parameter %d\n", count);
- return 0;
- }
- static ssize_t
- crime_ioctl(struct inode* inode, struct file* file, unsigned int cmd, unsigned long data) {
- printk("crime_ioctl called with parameters %d %d\n", cmd, data);
- return 0;
- }
- module_init(crime_init);
- module_exit(crime_exit);
- MODULE_AUTHOR("author");
- MODULE_DESCRIPTION("description");
- MODULE_LICENSE("license");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement