Last active
October 4, 2020 05:03
-
-
Save sepfy/88cbb308ed793279d9bb4cbe05ddfef5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ssize_t | |
mydev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos) | |
{ | |
char tmp[] = "Kernel says hello"; | |
printk("[%s][%d]\n", __func__, __LINE__); | |
copy_to_user(buf, tmp, sizeof(tmp)); | |
*pos = 0; | |
return 0; | |
} | |
static ssize_t | |
mydev_write(struct file *filp, const char __user *buf, | |
size_t count, loff_t *pos) | |
{ | |
char tmp[128] = {0}; | |
printk("[%s][%d]\n", __func__, __LINE__); | |
copy_from_user(tmp, buf, sizeof(tmp)); | |
printk("%s", tmp); | |
return count; | |
} | |
static int mydev_open(struct inode *inode, struct file *filp) | |
{ | |
printk("[%s][%d]\n", __func__, __LINE__); | |
return 0; | |
} | |
static int | |
mydev_release(struct inode *inode, struct file *filp) | |
{ | |
printk("[%s][%d]\n", __func__, __LINE__); | |
return 0; | |
} | |
static struct file_operations | |
mydev_fops = { | |
.owner = THIS_MODULE, | |
.open = mydev_open, | |
.release = mydev_release, | |
.read = mydev_read, | |
.write = mydev_write, | |
.unlocked_ioctl = mydev_ioctl, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment