how to use the function copyout()
Felix-KM
Felix-KM at yandex.ru
Tue Jul 26 07:46:31 GMT 2005
> I think that could work (only an idea, not tested):
>
>
> struct Region
> {
> void * p;
> size_t s;
> };
>
>
> #define IOBIG _IOWR ('b', 123, struct Region)
>
>
> userland:
>
> char data[1000];
> struct Region r;
>
> r.p = data;
> r.s = sizeof data;
> int error = ioctl (fd, IOBIG, &r);
>
>
> kernel:
> int my_ioctl(..., caddr_t data, ...)
> {
> ...
> char data[1000];
> ...
> return copyout(data, ((struct Region *) data)->p, ((struct Region *)
> data)->s);
> }
>
>
> Have a try and tell us if it works.
>
>
> Norbert
>
Yes! Now the program works!
I have changed the code in this way:
struct Region
{
void * p;
size_t s;
};
#define IOBIG _IOWR ('b', 123, struct Region)
---- driver ----
struct my_softc {
...
short unsigned int B;
};
...
static int
my_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag,
struct thread *td)
{
struct my_softc *my_sc;
int unit, error;
unit = minor(dev);
my_sc = (struct my_softc *)devclass_get_softc(my_devclass, unit);
if (my_sc == NULL)
return (ENXIO);
switch(cmd)
{
...
case IOCTL_GET_B:
error = copyout(&my_sc->B, (((struct Datas *)data)->d)+0x1850, sizeof(my_sc->B));
break;
default:
break;
}
return 0;
}
---user program ----------------------
...
short unsigned int data[32768];
struct Region r;
int
main(int argc, char *argv[])
{
...
r.p = data;
r.s = sizeof data;
if (ioctl(fd0, IOCTL_GET_B, &r) == -1)
err(1, "IOCTL_GET_B");
...
}
Now I have access to each element of the array (e.g. 0x1850).
Thank you very much!
More information about the freebsd-hackers
mailing list