how to use the function copyout()

From: Felix-KM (Felix-KM_at_yandex.ru)
Date: 07/25/05

  • Next message: Steven Hartland: "Re: aac_pci.c Patch (support for HP ML110 G2)"
    Date: Mon, 25 Jul 2005 16:35:20 +0400 (MSD)
    To: freebsd-hackers@freebsd.org
    
    

    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"


  • Next message: Steven Hartland: "Re: aac_pci.c Patch (support for HP ML110 G2)"

    Relevant Pages

    • [PATCH] get rid if __cpuinit and __cpuexit
      ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
      (Linux-Kernel)
    • [PATCH 8/9] irq-remove: driver trivial
      ... unsigned int i; ... unsigned int handled = 0; ... struct ata_port *ap; ... Read the interrupt register and process for the devices that have them pending. ...
      (Linux-Kernel)
    • [RFC/PATCH] Winbond CIR driver for the WPCD376I chip (ACPI/PNP id WEC1022)
      ... The driver currently supports receiving IR commands and wake from sleep/power-off. ... The input syscalls all seem to use an int for the scancode (which will be at least 32 bits on any platform which has ... unsigned int last_keycode; ... goto set_timer; ...
      (Linux-Kernel)
    • Re: 2.6.26-rc2 hosed X?
      ... int new); ... struct pci_controller *hose; ... * vblank events since the system was booted, ... unsigned int rotated2_tiled; ...
      (Linux-Kernel)
    • [EXPL] Snort Back Orifice Preprocessor Buffer Overflow (Exploit)
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... * char buf1; ... unsigned int ret_off; // offset from buf1 to saved eip ...
      (Securiteam)