how to use the function copyout()

Scott Long scottl at samsco.org
Tue Jul 26 15:39:36 GMT 2005


Felix-KM wrote:
>>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)
> 

Unless your ioctl handler is going to modify values in the Region struct
and pass them back out to userland, you should just use _IOR instead of 
_IORW.

Scott


More information about the freebsd-hackers mailing list