hi,
I need to copy strings from kernel space to user space and vice versa.
Currently if I do the following on the shell
Write from user--> kernel :echo -n abcedef > /dev/stringdrvr
read from kernel-->user :cat /dev/stringdrvr
It only returns the last character 'f' and not entire string.
Also how do i copy 2 dimensional array data
Here is my code.
size_t count=99;
ssize_t stringdrvr_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
copy_to_user(buf,stringdrvr_buffer,99);
if (*f_pos == 0) { *f_pos+=1; return 1; }
else { return 0; }
}
ssize_t stringdrvr_write( struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
char *tmp;
tmp=buf+count-1;
copy_from_user(stringdrvr_buffer,tmp,99);
return 1;
}
---------- Post updated at 04:11 PM ---------- Previous update was at 03:32 PM ----------
oops...i knw what went wrong.... here is workin code
read:
int len, err;
if( counter <= 0 )
return 0;
err = copy_to_user(buf,string,counter);
if (err != 0)
return -EFAULT;
len = counter;
counter = 0;
return len;
write:
int err;
err = copy_from_user(string,buf,count);
if (err != 0)
return -EFAULT;
counter += count;
//printk("<1>Counted = %d\n",count);
return count;