Using open system call in KLD
Anupam Deshpande
anupamdeshpande at gmail.com
Mon Mar 6 02:10:11 PST 2006
On 3/5/06, Robert Watson <rwatson at 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 = 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
>
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
More information about the freebsd-hackers
mailing list