From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 5 17:23:50 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 1854716A420 for ; Sun, 5 Mar 2006 17:23:50 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4B2E243D53 for ; Sun, 5 Mar 2006 17:23:49 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id DD63B46B1D; Sun, 5 Mar 2006 12:23:27 -0500 (EST) Date: Sun, 5 Mar 2006 17:23:48 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Anupam Deshpande In-Reply-To: <25da4ac50603050701j3fc63843oe288f6d34b67d115@mail.gmail.com> Message-ID: <20060305172046.V51568@fledge.watson.org> References: <25da4ac50603050701j3fc63843oe288f6d34b67d115@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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: Sun, 05 Mar 2006 17:23:50 -0000 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 = curthread; > int fd; > o.path = "/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 getting the file descriptor from the right place. You'll probably find that the value you're getting back is EFAULT, indicating that the path pointer was not valid for a user process. Robert N M Watson > o.flags = O_CREAT | O_RDWR | O_APPEND; > o.mode = 777; > fd = open(td,&a); > printf("\nFile descriptor = %d",fd); > c.fd = fd; > close(td,&c); > } > > > Can anyone help me in this regard? > > TIA, > Anupam Deshpande > _______________________________________________ > 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" >