Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2001 10:53:24 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        "Eugene L. Vorokov" <vel@bugz.infotecs.ru>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: accessing files from kld module
Message-ID:  <3B3A1D94.5895DCD0@mindspring.com>
References:  <200106271617.f5RGH0243541@bugz.infotecs.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
"Eugene L. Vorokov" wrote:
> probably this question was asked here many times before,
> but I'm new to kernel mode hacks ... Is it somehow possible
> to access files from my kld module ? I have seen functions
> like printf(), MALLOC() for kernel mode, but nothing like
> open() ... using open() syscall directly seems impossible
> too because generally I don't have struct proc entry.
> 
> I would be very thankful for any information regarding this issue.

Kernel file handling in FreeBSD is significantly inferior
to that of many other operating systems; notably, AIX has
vastly superior file handling, which can be used from its
kernel threads, etc. (AIX has the best I've seen).

For FreeBSD, you can do file handling, with some effort;
the main problem is that vnode pointer references are not
considered "opens" by the resource tracking system (as
they are in SVR4 and Solaris and several other SVR3/SVR4
derived OS's).

The place you want to look is:

	/sys/kern/vfs_vnops.c

I/O is tricky; if you are reading/writing to a buffer in
kernel space, you have to use the combined vn_rdwr()
routine.  Make sure you set segflg to UIO_SYSSPACE.  This
really is easier than direct calls to VOP_WRITE(), or
trying to allocate and manage fp's without a real process,
and calling vn_read() or vn_write(), which, contrary to
their names, do not operate on vnodes, they operate on fp's.

You won't be able to use ioctl(), poll(), kqfilter(), etc.,
without at least consing up a fake fp, and since the parts
used vary, you'd be better off with a real one.

Good luck.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3B3A1D94.5895DCD0>