operate file in kernel space

John Baldwin jhb at freebsd.org
Mon Mar 26 14:48:09 UTC 2012


On Sunday, March 25, 2012 10:41:09 pm Yong Fan wrote:
> Hi all,
> 
> I want to operate file in kernel space.
> At present, I have found the following kernel routines, which operate file:
> Kern_open(), kern_close(), kern_readv() and kern_writev().
> Now, I have some doubt about these routines?
> 1 kern_open() doesn't return a file handle or file pointer?
> As we know, filp_open(), which is a Linux kernel routine, returns a file 
pointer.
> ZwCreateFile(), which is a Windows kernel routine, returns a file handle.
> 
> 2 how can I "seek" a file in kernel space?
> The function of "seek" routine is similar with generic_file_llseek()(Linux) 
or ZwSetInformationFile()(windows).

file descriptors in FreeBSD are generally tied to a file descriptor table (so 
a process).  What you can do is locate a vnode directly (e.g. using namei() to 
do a pathname lookup) and then use vn_rdwr() to access the data in the file.  
vn_rdwr() accepts a uio and you would manage your own "seek" location and that 
gets set in the uio_offset of the uio you pass to vn_rdwr().

-- 
John Baldwin


More information about the freebsd-drivers mailing list