From owner-freebsd-drivers@FreeBSD.ORG Mon Dec 27 19:29:12 2010 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1CBB1106566C for ; Mon, 27 Dec 2010 19:29:12 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id E4FD48FC0C for ; Mon, 27 Dec 2010 19:29:11 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 8951F46B06; Mon, 27 Dec 2010 14:29:11 -0500 (EST) Received: from John-Baldwins-Macbook-Pro.local (c-68-36-150-83.hsd1.nj.comcast.net [68.36.150.83]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 771BD8A009; Mon, 27 Dec 2010 14:29:10 -0500 (EST) Message-ID: <4D18E905.1060000@FreeBSD.org> Date: Mon, 27 Dec 2010 14:29:09 -0500 From: John Baldwin User-Agent: Thunderbird 2.0.0.24 (Macintosh/20100228) MIME-Version: 1.0 To: Mohammad Hedayati References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Mon, 27 Dec 2010 14:29:10 -0500 (EST) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-0.9 required=4.2 tests=BAYES_00,RDNS_DYNAMIC autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: freebsd-drivers@freebsd.org Subject: Re: Inappropriate ioctl for device X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Dec 2010 19:29:12 -0000 Mohammad Hedayati wrote: > I'm writing a simple char device. So far everything went so good > (read/write), but here I'm going to add support for ioctl. > > int > ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td) > { > int error = 0; > uprintf("Here...\n"); > return(error); > } > and I'm calling it here: > > len = ioctl(cd, 0); > perror("ioctl"); > > but when runnig it says: > > ioctl: Inappropriate ioctl for device > > where's the problem? 0 is not a valid ioctl code. A valid ioctl code has to have at least one of IOC_VOID, IOC_IN, or IOC_OUT set. Also, if it has either IOC_IN or IOC_OUT set, it must have a non-zero size field. You should use one of the _IO* macros from to define a valid ioctl code and pass that to your driver. -- John Baldwin