Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jul 2005 11:46:23 +0400 (MSD)
From:      "Felix-KM" <Felix-KM@yandex.ru>
To:        NKoch@demig.de
Cc:        freebsd-hackers@freebsd.org
Subject:   RE: how to use the function copyout()
Message-ID:  <42E5EA4F.00000A.07557@colgate.yandex.ru>
In-Reply-To: <000001c59129$6099b560$4801a8c0@ws-ew-3.W2KDEMIG>
References:  <000001c59129$6099b560$4801a8c0@ws-ew-3.W2KDEMIG>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
> 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!



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?42E5EA4F.00000A.07557>