Re: how to use the function copyout()

From: Kamal R. Prasad (kamalpr_at_yahoo.com)
Date: 07/25/05

  • Next message: Norbert Koch: "RE: how to use the function copyout()"
    Date: Mon, 25 Jul 2005 06:05:28 -0700 (PDT)
    To: Felix-KM@yandex.ru, freebsd-hackers@freebsd.org
    
    

    Im not sure of the bug in your code, but you have got
    to assume that copyout() would fail if the user/kernel
    addr passed to it is not accessible.

    regards
    -kamal

    --- Felix-KM <Felix-KM@yandex.ru> wrote:

    > I can't understand how to use the function
    > copyout().
    > It is necessary to write the data from a device
    > driver to the
    > array defined in user program.
    > I do it this way:
    >
    > #define IOCTL_GET_B _IOWR("F", 127, 0x4)
    >
    > ---- 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, data,
    > sizeof(my_sc->B));
    > switch (error)
    > {
    > case 0:
    > printf(" IOCTL_GET_B: %d\n", my_sc->B);
    > break;
    > case EFAULT:
    > printf("EFAULT\n");
    > break;
    > case EIO:
    > printf("EIO\n");
    > break;
    > case ENOMEM:
    > printf("ENOMEM\n");
    > break;
    > case ENOSPC:
    > printf("ENOSPC\n");
    > break;
    > }
    > break;
    > default:
    > break;
    > }
    > return 0;
    > }
    >
    > ---user program ----------------------
    >
    > ...
    >
    > short unsigned int Data[32768];
    >
    > int
    > main(int argc, char *argv[])
    > { ...
    >
    > if (ioctl(fd0, IOCTL_GET_B, Data) == -1)
    > err(1, "IOCTL_GET_B");
    >
    > ...
    > }
    >
    > -------
    >
    > Here I get EFAULT.
    >
    > What have I done wrong? How can I do it correctly?
    > _______________________________________________
    > freebsd-hackers@freebsd.org mailing list
    >
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    > To unsubscribe, send any mail to
    > "freebsd-hackers-unsubscribe@freebsd.org"
    >

    ------------------------------------------------------------
    Kamal R. Prasad
    UNIX systems consultant
    http://www.kamalprasad.com/
    kamalp@acm.org

    In theory, there is no difference between theory and practice. In practice, there is.
    ------------------------------------------------------------

                    
    ____________________________________________________
    Start your day with Yahoo! - make it your home page
    http://www.yahoo.com/r/hs
     
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Norbert Koch: "RE: how to use the function copyout()"

    Relevant Pages

    • Re: spurious C warnings..
      ... 6809 home system - so I still tend to avoid making assumptions ... Anyway, your explanation makes sense. ... It first tries for int, ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Using Get() and Set() instead of accessing the variable directly
      ... I feel as though accessing variables directly is just bad practice. ... I can access private/protected variables, but when I divide up the class ... int m_x; ... I don't know if the compiler treats it as accessing the variable directly or ...
      (microsoft.public.vc.mfc)
    • Re: Making a function "forget" a variable
      ... it was a theoretical question. ... practice I would only be slightly worried of inadvertENtly ... void f1{ ... int v1=10; ...
      (comp.lang.lisp)
    • Re: Beginner has trouble with SDL in foll-screen mode.
      ... In full-screen mode everything is sheared off into wavy lines, ... Uint8 green, ... int x, y, t; ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: Beginner has trouble with SDL in foll-screen mode.
      ... In full-screen mode everything is sheared off into wavy lines, ... Uint8 green, ... int x, y, t; ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)