Problems implementing write function of a character device
Problems implementing write function of a character device
- Subject: Problems implementing write function of a character device
- From: sanjay yaragatti <email@hidden>
- Date: Wed, 13 Sep 2006 09:54:54 +0100 (BST)
I am implementing write func for a character device.
I am using the accessor methods uio_curriovlen(uio)
and uio_curriovbase(uio) provided in the <sys/uio.h>
file to get the length value of the current iovec
associated with the given uio and the base address of
the current iovec associated with the given uio
respectively.However, both the calls are returning
zero as the return value.Hence unable to copy the data
from userspace to kernel space.Even tried using
uiomove() inplace of copyin() but doesnt work. I have
attached the code for reference.. Please let me know
if something wrong in the code.
INT32 device_write
(
dev_t device, struct uio *uio, int ioflag
)
{
INT ret = SUCCESS;
PUCHAR tmp_buff = NULL;
UINT32 minor_num;
user_size_t buff_len = 0, buff_base = 0;
/* Get the minor number */
minor_num = minor(device);
buff_len = uio_curriovlen(uio);
buff_base = uio_curriovbase(uio);
IOLog ("uio_curriovlen is %d & uio_curriovbase
is %d\n ",buff_len,buff_base);
tmp_buff = (PUCHAR) mem_alloc(buff_len);
if (NULL == tmp_buff)
{
IOLog("%s: Buffer is NULL\n", __FUNCTION__);
return FAILURE;
}
if(ret = copyin(buff_base, tmp_buff,buff_len)!= 0)
{
mem_free(tmp_buff,buff_len);
IOlog("%s: Copy from user failed\n",
__FUNCTION__);
return FAILURE;
}
*(tmp_buff+ buff_len ) = 0;
}
--- Terry Lambert <email@hidden> wrote:
> On Sep 12, 2006, at 2:13 AM, sanjay yaragatti wrote:
> >
> > Hi all,
> > I am writing a kernel driver.I have
> regestered it
> > as character device. I am unable to implement the
> > device write method (dev_write( dev_t device,
> struct
> > uio *uio, int ioflag)) since I don't know how to
> > retrieve the buffer from struct uio.
> >
> > However on trying to dereference uio as
> > uio->uio_iov->iov_base gave a compilation error.
> >
> > Is there a KPI to retrieve the buffer sent from
> user
> > space?
>
> You may want to read /usr/include/sys/uio.h...
>
>
> /*
> * uio_curriovbase - return the base address of the
> current iovec
> associated
> * with the given uio_t. May return 0.
> */
> user_addr_t uio_curriovbase( uio_t a_uio );
>
>
> You can also look at the kernel sources; in this
> case, the function is
> implemented in:
>
>
>
<http://www.opensource.apple.com/darwinsource/10.4.7.ppc/xnu-792.6.76/bsd/kern/kern_subr.c
>
> >
>
> -- Terry
>
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden