From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 5 18:41: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 1A00F16A420 for ; Sun, 5 Mar 2006 18:41:50 +0000 (GMT) (envelope-from pranav.sawargaonkar@gmail.com) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.195]) by mx1.FreeBSD.org (Postfix) with ESMTP id 55D9B43D45 for ; Sun, 5 Mar 2006 18:41:49 +0000 (GMT) (envelope-from pranav.sawargaonkar@gmail.com) Received: by wproxy.gmail.com with SMTP id i12so1240601wra for ; Sun, 05 Mar 2006 10:41:48 -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:mime-version:content-type; b=qp8SLMpv5ipYvgSaTilN8kCNjJ2V4eb0QpDHRpPfUKTBaBH7aR9ZZErhY4JejRGW1xgfMtA1NB2Nm4ZyY3K1GkJBYpb68/d/JRIBt1Ywfsd/bPbB3WvkYi6hJ8k/KxsDbY0R3Rmfx6Z9QIMBmLQ4J/GA1j9ch7+AnyuR42ztRds= Received: by 10.54.62.3 with SMTP id k3mr4084352wra; Sun, 05 Mar 2006 10:41:48 -0800 (PST) Received: by 10.54.119.2 with HTTP; Sun, 5 Mar 2006 10:41:47 -0800 (PST) Message-ID: <5007e1a40603051041wc59ae7ar97d71ac3746f611f@mail.gmail.com> Date: Mon, 6 Mar 2006 00:11:47 +0530 From: "Pranav Sawargaonkar" To: anupamdeshpande@gmail.com MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 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 18:41:50 -0000 On 3/5/06, Anupam Deshpande wrote: > > >Hello, > > I have used open system call in KLD to create >a file. But afte= r > >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. > > Instead of >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"; >o.flags =3D O_CREAT | O_RDWR | O_APPEND; >o.mode =3D 777; >fd =3D open(td,&a); >printf("\nFile descriptor =3D %d",fd); >c.fd =3D fd; >close(td,&c); >} U need to change it to 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"; o.flags =3D O_CREAT | O_RDWR | O_APPEND; o.mode =3D 777; />>/fd =3D open(td,&a); /*Beacuse open passes UIO_USERSPACE and you are using open from KLD thus you need to change it to UIO_SYSSPACE and also need to use kern_open() which is defined in #include as below*/ fd=3Dkern_open(td,o.path, UIO_SYSSPACE, o.flags,o.mode); printf("\nFile descriptor =3D %d",fd); c.fd =3D fd; close(td,&c); } -Pranav Sawargaonkar