Opening and wriiting to file in Kern

Scott Long scottl at freebsd.org
Sun Feb 6 03:33:48 PST 2005


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.

If you mist do this, the general set of steps are:

1. use namei() to convert a pathname to a vnode
2. Use vn_open(), vn_rdwr(), and vn_close() to operate on the vnode.
3. Observe proper vnode locking and reference counting with vref(),
vn_lock(), and vput()

Scott


More information about the freebsd-hackers mailing list