From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 25 13:05:29 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDF5616A41F for ; Mon, 25 Jul 2005 13:05:29 +0000 (GMT) (envelope-from kamalpr@yahoo.com) Received: from web52709.mail.yahoo.com (web52709.mail.yahoo.com [206.190.48.232]) by mx1.FreeBSD.org (Postfix) with SMTP id 67CDD43D48 for ; Mon, 25 Jul 2005 13:05:29 +0000 (GMT) (envelope-from kamalpr@yahoo.com) Received: (qmail 59035 invoked by uid 60001); 25 Jul 2005 13:05:28 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=zo+6u6Gf6JTd8fTG6Q2f83VPmnEyq8+3RHhfRgBoUPPzRnd2wUq0e1/KGDg/8hFnoCum3cilQXYw/9mylA7qBxUFYEQCT2fnWUzQu/FJhBwfnHTDKF+KhVzeK6HV1uqJQPitJTX6GYEy80bWQ8fIOYSs2KPHDcLDUTrJJ/wjQyE= ; Message-ID: <20050725130528.59033.qmail@web52709.mail.yahoo.com> Received: from [64.186.168.226] by web52709.mail.yahoo.com via HTTP; Mon, 25 Jul 2005 06:05:28 PDT Date: Mon, 25 Jul 2005 06:05:28 -0700 (PDT) From: "Kamal R. Prasad" To: Felix-KM@yandex.ru, freebsd-hackers@freebsd.org In-Reply-To: <42E4DC88.000006.21996@camay.yandex.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: Subject: Re: how to use the function copyout() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: kamalp@acm.org List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2005 13:05:30 -0000 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 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