Hi!
Goal, when the user do :
# head -1 /dev/miscdrv
The driver prints: Hello World!
Steps:
# Make
# insmod misc.ko
# head -1 /dev/miscdrv
Why my driver doesn't work ?
What is worg with my read operation?
static ssize_t
misc_drv_read(struct file *filp, char __user * buf, size_t count, loff_t * offp){
int nbytes;
char * string = "hello World";
nbytes = copy_to_user(buf, string, 12);
return nbytes;
}
--
Lucas Tanure Brazil
Attachment:
Makefile
Description: Binary data
#include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/device.h> #include <linux/miscdevice.h> #include <linux/uaccess.h> /* copy_(to,from)_user */ #define MYDEV_NAME "miscdrv" static ssize_t misc_drv_read(struct file *filp, char __user * buf, size_t count, loff_t * offp){ int nbytes; char * string = "hello World"; nbytes = copy_to_user(buf, string, 12); return nbytes; } static ssize_t misc_drv_write(struct file *filp, const char __user * buf, size_t count, loff_t * offp) { return 0; } static const struct file_operations misc_drv_fops = { .read = misc_drv_read, .write = misc_drv_write, }; static struct miscdevice my_misc_device = { .minor = MISC_DYNAMIC_MINOR, .name = MYDEV_NAME, .fops = &misc_drv_fops, }; static int __init my_init(void){ dev_info(my_misc_device.this_device, "Registering Device\n"); if (misc_register(&my_misc_device)) { pr_err("Couldn't register device misc, %d.\n", my_misc_device.minor); return -EBUSY; } return 0; } static void __exit my_exit(void) { dev_info(my_misc_device.this_device, "Unregistering Device\n"); misc_deregister(&my_misc_device); } module_init(my_init); module_exit(my_exit); MODULE_AUTHOR("Lucas Tanure"); MODULE_DESCRIPTION("Test Misc Device"); MODULE_LICENSE("GPL v2");
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies