help with copy_to/from_user char device driver


 
Thread Tools Search this Thread
Top Forums Programming help with copy_to/from_user char device driver
# 1  
Old 11-03-2010
help with copy_to/from_user char device driver

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.
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
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;


Last edited by pludi; 11-03-2010 at 06:40 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Programming

regarding device driver

Hi All, I have a device driver that uses UARTserial port to write/read to-from a device. That device driver is working fine on FC3 machine( kernel version 2.6.12)... Now I am switching to FC9 (kernel version 2.6.25.11-97).I have changed the interrupt flag SA_INTERRUPT to IRQF_DISABLED... (0 Replies)
Discussion started by: rajuprade
0 Replies

2. UNIX for Advanced & Expert Users

help regarding device driver

Hi All, I have a device driver that uses UARTserial port to write/read to-from a device. That device driver is working fine on FC3 machine( kernel version 2.6.12)... Now I am switching to FC9 (kernel version 2.6.25.11-97).I have changed the interrupt flag SA_INTERRUPT to IRQF_DISABLED... (0 Replies)
Discussion started by: rajuprade
0 Replies

3. Programming

Network device driver

HI, I am writing a network device driver for RTL8139c card on 2.6.18 kernel ... I am facing few queries listed below 1. Can i able to at all write a driver for RTL8139C or Realtek had designed new chip for 2.6 series kernel? 2. If no then which driver file 2.6.18 uses .. Is it 8139too.c or... (1 Reply)
Discussion started by: niketan
1 Replies

4. Solaris

SUNWglmr -- rasctrl environment monitoring driver for i2c or SCSI device driver ?

I've been researching minimizeing Solaris 8 and found that on the web page http://www.sun.com/bigadmin/content/packagelist/s8u7PkgList/p2.html the package SUNWglmr is listed as "rasctrl environment monitoring driver for i2c, (Root) (32-bit)" while in the document "Solaris 8 minimize-updt1.pdf"... (1 Reply)
Discussion started by: roygoodwin
1 Replies
Login or Register to Ask a Question