How to get data from kernel module ?

Patrick Mahan mahan at mahan.org
Sat May 8 22:14:26 UTC 2010


Lukáš Czerner wrote:
> Hi,
> 
> I am creating a kernel module and I need to get some information from
> that module. I can do this with ioctl and pass the data to the
> user space but it seems a bit unpractical to me, because I do not know 
> the amount of the data - it can differ. I do not know of any way to
> pass a list of structures to the userspace through ioctl - is there
> any?
> 
> So my question is, is there any standard way in FreeBSD to do this ?
> In linux I would probably use the sysfs, but in FreeBSD I can not find
> anything similar, except just creating some virtual filesystem on my
> own and obviously this is not what I want to do.
> 


You could use ioctl().  You will need to make two calls.  Once without
the data pointer and once with.  Take a look at
src/sbin/ifconfig/ifmedia.c

Take a look at sysctl(3) in particular, if you have the sources online
look at src/usr.bin/netstat/inet.c or src/usr.bin/netstat/route.c.  You
will need to also look at their corresponding kernel code.

Or finally, you could use kvm(3).

Good luck,

Patrick



More information about the freebsd-hackers mailing list