Opening and wriiting to file in Kern

Peter Pentchev roam at ringlet.net
Sun Feb 6 04:41:13 PST 2005


On Sun, Feb 06, 2005 at 04:22:41AM -0800, Kamal R. Prasad wrote:
> 
> --- Scott Long <scottl at freebsd.org> wrote:
> 
> > Ashwin Chandra wrote:
> > 
> > > Does anyone know the correct calls to open a file,
> > write to it, and close it, IN *kernel* mode. 
> > > 
> > > Ash
> > 
> > There is no common API for doing this, which is
> > pretty much on purpose. 
> >   First, you need to ask yourself why your task
> > needs it done in the 
> > kernel and not in userland.
> 
> A feature implemented within the kernel that requires
> making stuff persistent would almost certainly require
> file I/O. For that matter, a kernel (module) that
> reads a configuration file will also need the same
> facility. I don't see anything wrong with providing a
> stream (like) interface to the filesystem.

While there might indeed be nothing wrong with it, besides added
complexity, the traditional way to do it would be to have a userland
configuration utility that communicates with the kernel module either
via ioctl's on some standard device, or via ioctl's or reading/writing
of a driver-specific device.  This has the advantage of being a bit more
portable - while different OS's implement disk/file I/O within the
kernel in wildly different ways, all OS's provide relatively simple ways
for a kernel module to define a new device and handle ioctl's to it, and
all OS's provide basically the same userland-to-kernel interface for
having a program open a device and issue ioctl's to it :)

Another way would be, again, communication between a userland utility
and a kernel module, but this time using mmap'd files/devices instead of
ioctl's.

G'luck,
Peter

-- 
Peter Pentchev	roam at ringlet.net    roam at cnsys.bg    roam at FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
This sentence was in the past tense.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20050206/0cab1bf5/attachment.bin


More information about the freebsd-hackers mailing list