Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/proc_fs.h>
- #include <asm/uaccess.h>
- static ssize_t my_read(struct file *instance, char __user *buffer, size_t max_bytes_to_write, loff_t *offset)
- {
- char kernel_buffer[10];
- size_t to_copy, not_copied;
- if (*offset > 5)
- return 0;
- strncpy(kernel_buffer, "benis\n", sizeof(kernel_buffer));
- to_copy = min(strlen(kernel_buffer), max_bytes_to_write);
- not_copied = copy_to_user(buffer, kernel_buffer, to_copy);
- *offset += to_copy - not_copied;
- return to_copy - not_copied;
- }
- static const struct file_operations proc_fops =
- {
- .owner = THIS_MODULE, // Fürs handling intern, u.a. für die erkennung ob strukturen leaken
- .read = my_read,
- };
- static struct proc_dir_entry *my_proc_file;
- #define PROC_FILE_NAME "myFile"
- static int __init blah_init(void)
- {
- my_proc_file = proc_create(PROC_FILE_NAME, 0666, NULL, &proc_fops);
- if (my_proc_file == NULL)
- return 1;
- return 0;
- }
- static void __exit blah_exit(void)
- {
- remove_proc_entry(PROC_FILE_NAME, NULL);
- }
- module_init(blah_init);
- module_exit(blah_exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement