Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef devwrite__c
- #define devwrite__c
- #include <linux/init.h> // Macros used to mark up functions e.g. __init __exit
- #include <linux/module.h> // Core header for loading LKMs into the kernel
- #include <linux/device.h> // Header to support the kernel Driver Model
- #include <linux/kernel.h> // Contains types, macros, functions for the kernel
- #include <linux/fs.h> // Header for the Linux file system support
- #include <asm/uaccess.h> // Required for the copy to user function
- #include <linux/slab.h>
- #include "outpmodes.c"
- /** @brief This function is called whenever the device is being written to from user space i.e.
- * data is sent to the device from the user. The data is copied to the message[] array in this
- * LKM using the sprintf() function along with the length of the string.
- * @param filep A pointer to a file object
- * @param buffer The buffer to that contains the string to write to the device
- * @param len The length of the array of data that is being passed in the const char buffer
- * @param offset The offset if required
- */
- static ssize_t dev_write(struct file *filep, const char *buffer, size_t len, loff_t *offset){
- //sprintf(message, "%s(%zu letters)", buffer, len); // appending received string with its length
- char tmpMsg[256] = {0};
- copy_from_user(tmpMsg,buffer, len);
- if(strncmp(tmpMsg, forward, strlen(forward)) == 0){
- direction = 1;
- printk(KERN_INFO "Forward direction");
- return strlen(tmpMsg);
- } else if(strncmp(tmpMsg, back, strlen(back)) == 0){
- direction = -1;
- printk(KERN_INFO "Back direction");
- return strlen(tmpMsg);
- } else if(strncmp(tmpMsg, delete, strlen(delete)) == 0){
- printk(KERN_INFO "Delete");
- message[0] = 0;
- size_of_message = 0;
- return strlen(tmpMsg);
- }
- strcpy(message, tmpMsg);
- size_of_message = len; // store the length of the stored message
- *offset += len;
- printk(KERN_INFO "EBBChar: Received %zu characters from the user\n", len);
- return len;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement