Sponsored Content
Top Forums Programming help with copy_to/from_user char device driver Post 302468735 by dragonpoint on Wednesday 3rd of November 2010 05:11:30 PM
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
 

4 More Discussions You Might Find Interesting

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

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

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

4. 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
kvm_kread(3KVM) 					    Kernel VM Library Functions 					   kvm_kread(3KVM)

NAME
kvm_kread, kvm_kwrite, kvm_uread, kvm_uwrite - copy data to or from a kernel image or running system SYNOPSIS
cc [ flag... ] file... -lkvm [ library...] #include <kvm.h> ssize_t kvm_kread(kvm_t *kd, uintptr_t addr, void *buf, size_t nbytes); ssize_t kvm_kwrite(kvm_t *kd, uintptr_t addr, void *buf, size_t nbytes); ssize_t kvm_uread(kvm_t *kd, uintptr_t addr, void *buf, size_t nbytes); ssize_t kvm_uwrite(kvm_t *kd, uintptr_t addr, void *buf, size_t nbytes); DESCRIPTION
The kvm_kread() function transfers data from the kernel address space to the address space of the process. nbytes bytes of data are copied from the kernel virtual address given by addr to the buffer pointed to by buf. The kvm_kwrite() function is like kvm_kread(), except that the direction of the transfer is reversed. To use this function, the kvm_open(3KVM) call that returned kd must have specified write access. The kvm_uread() function transfers data from the address space of the processes specified in the most recent kvm_getu(3KVM) call. nbytes bytes of data are copied from the user virtual address given by addr to the buffer pointed to by buf. The kvm_uwrite() function is like kvm_uread(), except that the direction of the transfer is reversed. To use this function, the kvm_open(3KVM) call that returned kd must have specified write access. The address is resolved in the address space of the process speci- fied in the most recent kvm_getu(3KVM) call. RETURN VALUES
On success, these functions return the number of bytes actually transferred. On failure, they return -1. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
kvm_getu(3KVM), kvm_nlist(3KVM), kvm_open(3KVM), attributes(5) SunOS 5.11 2 May 2002 kvm_kread(3KVM)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy