Results 1 to 2 of 2
Hi ,
I am new to linux and was making a module in which user can read as well as write to a device file.the following is my code where ...
- 01-27-2012 #1Just Joined!
- Join Date
- Jan 2012
- Posts
- 1
how to write on a device file using copy_from_user()
Hi ,
I am new to linux and was making a module in which user can read as well as write to a device file.the following is my code where read is working fine but not the write function.
MODULE_LICENSE("DUAL BSD/GPL");
char message[80];
char *msg_ptr;
int dev_major = 0;
int dev_minor = 0;
struct cdev *cdev;
ssize_t dev_read(struct file *filp,char __user *buf,size_t count,loff_t *offset)
{
int i;
i=copy_to_user(buf,msg_ptr,count);
printk(KERN_ALERT"buff:%s",buf);
if(buf == '\0')
{
printk("you idiot dont show your face again");
return 0;
}
return 0;
}
ssize_t dev_write(struct file *filp,const char __user *buf,size_t count,loff_t *offset)
{
int j;
msg_ptr = kmalloc(20*sizeof(char),GFP_KERNEL);
//for(j=0;j<count;j++)
copy_from_user(msg_ptr,buf,count);
//printk(KERN_ALERT"msg_ptr:%s",msg_ptr);
return 0;
}
when i make a char node and then use echo hi >/dev/my_dev then it prints hi but writes infintely as seen in /var/log/messages . Please help.reply as soon as possible.
regards
karan
- 01-28-2012 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Please move this to the Kernel forum. This is NOT a general programming issue!
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote