How to access a user space file from kernel space in FreeBSD.

Polytropon freebsd at edvax.de
Fri Mar 20 18:52:28 UTC 2020


On Fri, 20 Mar 2020 20:10:02 +0530, Arpan Palit wrote:
> I am working on (kernel)driver ioctl implementation for file read/write,
> where I need to know what are API's which can expose to read,write and
> close user space file from kernel space. In general I need to know the
> answer for the below questions.
> 
> i).   How to open a user space file from driver(kernel space) ?

With the open() system call. See "man 2 open" for details.



> ii).  How to create a new user space file from driver(kernel space) ?

With the creat() system call. See "man 2 creat" for details.



> iii). How to get file parameters like size of the file ?


With the stat() system call. See "man 2 stat" for details.



> iv). How to read/write the files from the driver(kernel space) ?

With the read() and write() system call. See "man 2 read"
and "man 2 write" for details.



If you have access to the standard C library (libc) from the
driver, you can also use fopen(), fstat(), fread(), fwrite(),
fgets(), fputs(), fscanf(), fprintf() et al. for file access.
See the corresponding manual pages in section 3.


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list