Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2006 00:11:47 +0530
From:      "Pranav Sawargaonkar" <pranav.sawargaonkar@gmail.com>
To:        anupamdeshpande@gmail.com
Cc:        freebsd-hackers@freebsd.org
Subject:   RE:Using open system call in KLD
Message-ID:  <5007e1a40603051041wc59ae7ar97d71ac3746f611f@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
On 3/5/06, Anupam Deshpande <anupamdeshpande@gmail.com> 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 <sys/syscallsubr.h>
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5007e1a40603051041wc59ae7ar97d71ac3746f611f>