Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Mar 2020 23:11:12 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        freebsd-hackers@freebsd.org
Subject:   Re: How to access a user space file from kernel space in FreeBSD.
Message-ID:  <eb2ddc43-76ca-4a92-92c7-730a40d8100d@grosbein.net>
In-Reply-To: <CAF3txfi1mNcmQEFDfOx01AA2aWza1Fteb7fisC%2BtWVQccoV77Q@mail.gmail.com>
References:  <CAF3txfi1mNcmQEFDfOx01AA2aWza1Fteb7fisC%2BtWVQccoV77Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
20.03.2020 21:40, 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) ?
> ii).  How to create a new user space file from driver(kernel space) ?
> iii). How to get file parameters like size of the file ?
> iv). How to read/write the files from the driver(kernel space) ?

It is not common behaviour for FreeBSD kernel land code to create/write files.
Generally there is some userland daemon doing this for some kernel subsystem.

However, there are cases when kernel does it by itself, f.e. writing coredump file,
creating new accounting file etc.

You may find some examples useful:

https://svnweb.freebsd.org/base/head/sys/kern/kern_sig.c?view=markup#l3623
https://svnweb.freebsd.org/base/head/sys/kern/kern_acct.c?view=markup#l223
https://svnweb.freebsd.org/base/head/sys/kern/kern_alq.c?view=markup#l448

I'm afraid this is basically undocumented and not encouraged
and you should consider adding some userland process for file manupilations.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eb2ddc43-76ca-4a92-92c7-730a40d8100d>