From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 6 10:10:11 2006 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 80E5C16A420 for ; Mon, 6 Mar 2006 10:10:11 +0000 (GMT) (envelope-from anupamdeshpande@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by mx1.FreeBSD.org (Postfix) with ESMTP id C356543D48 for ; Mon, 6 Mar 2006 10:10:10 +0000 (GMT) (envelope-from anupamdeshpande@gmail.com) Received: by wproxy.gmail.com with SMTP id 69so1101329wra for ; Mon, 06 Mar 2006 02:10:10 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=kLbE/yO1AbVf4bnfgGi5FjSMexkfuCWd7HcIUu8E2gdTtYmYXhqQEH9vYksUFKDpj4ryLr8f7E7wUPfTp9aw3s1I8Ru23UvfUGwvwSsOkBGnU6XNSR3+0r7YzK9KNuRkIKheXbb0EV2/qoTUIKFe3AaggaoJ2NFv7fm85q7fCzM= Received: by 10.65.211.10 with SMTP id n10mr2514917qbq; Mon, 06 Mar 2006 02:10:10 -0800 (PST) Received: by 10.64.27.7 with HTTP; Mon, 6 Mar 2006 02:10:10 -0800 (PST) Message-ID: <25da4ac50603060210j1902a751g9e4c615605f9def7@mail.gmail.com> Date: Mon, 6 Mar 2006 02:10:10 -0800 From: "Anupam Deshpande" To: "Robert Watson" In-Reply-To: <20060305172046.V51568@fledge.watson.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <25da4ac50603050701j3fc63843oe288f6d34b67d115@mail.gmail.com> <20060305172046.V51568@fledge.watson.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Using open system call in KLD X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2006 10:10:11 -0000 On 3/5/06, Robert Watson wrote: > > On Sun, 5 Mar 2006, Anupam Deshpande wrote: > > > I have used open system call in KLD to create a file. But after > > inserting the module the file is not created though the file descriptor > > returned is non zero. I also used close system call to close the file, > using > > the descriptor returned by open system call. > > I called the following function from my module: > > > > int f_open(void) > > { > > struct open_args o; > > struct close_args c; > > struct thread *td =3D curthread; > > int fd; > > o.path =3D "/home/file1.c"; > > There are a couple of things going on here: > > - open() accepts a pointer to a pathname in user address space. If this > code > is running in kernel, then the above string is in the kernel address > space. > You probably want to look at kern_open(), which accepts a path pointer > and > also an address space identifier, which can be set to UIO_SYSSPACE to > indicate that the path argument is being copied from a kernel address. > > - In kernel, system calls return (0) for success, or an error value, not = a > file descriptor number. This is placed in the thread context return > values > to be returned to user space. Specifically, in td->td_retval[0]. So > you're > not checking to make sure the call succeeded, and you're also not gett= ing > the file descriptor from the right place. You'll probably find that t= he > value you're getting back is EFAULT, indicating that the path pointer = was > not valid for a user process. > > Robert N M Watson > hello, I successfully created a file using kern_open(). Now I want to 'write to' or 'read from' the file.What functions should I use for that purpose? TIA, Anupam