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>
index | next in thread | raw e-mail
On 3/5/06, Anupam Deshpande <anupamdeshpande@gmail.com> wrote:
>
> >Hello,
> > 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.
>
>
Instead of
>int f_open(void)
>{
>struct open_args o;
>struct close_args c;
>struct thread *td = curthread;
>int fd;
>o.path = "/home/file1.c";
>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);
>}
U need to change it to
int f_open(void)
{
struct open_args o;
struct close_args c;
struct thread *td = curthread;
int fd;
o.path = "/home/file1.c";
o.flags = O_CREAT | O_RDWR | O_APPEND;
o.mode = 777;
/>>/fd = 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=kern_open(td,o.path, UIO_SYSSPACE, o.flags,o.mode);
printf("\nFile descriptor = %d",fd);
c.fd = fd;
close(td,&c);
}
-Pranav Sawargaonkar
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5007e1a40603051041wc59ae7ar97d71ac3746f611f>
