Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2006 02:10:10 -0800
From:      "Anupam Deshpande" <anupamdeshpande@gmail.com>
To:        "Robert Watson" <rwatson@freebsd.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Using open system call in KLD
Message-ID:  <25da4ac50603060210j1902a751g9e4c615605f9def7@mail.gmail.com>
In-Reply-To: <20060305172046.V51568@fledge.watson.org>
References:  <25da4ac50603050701j3fc63843oe288f6d34b67d115@mail.gmail.com> <20060305172046.V51568@fledge.watson.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 3/5/06, Robert Watson <rwatson@freebsd.org> 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



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