From owner-freebsd-hackers@FreeBSD.ORG Sat May 8 22:14:26 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BD2721065674 for ; Sat, 8 May 2010 22:14:26 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (ns.mahan.org [67.116.10.138]) by mx1.freebsd.org (Postfix) with ESMTP id 98FBF8FC1F for ; Sat, 8 May 2010 22:14:26 +0000 (UTC) Received: from Gypsy.mahan.org (crowTrobot [67.116.10.140]) by ns.mahan.org (8.13.6/8.13.6) with ESMTP id o48MJDRe061550; Sat, 8 May 2010 15:19:14 -0700 (PDT) (envelope-from mahan@mahan.org) Message-ID: <4BE5E241.2030604@mahan.org> Date: Sat, 08 May 2010 15:14:25 -0700 From: Patrick Mahan User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: =?UTF-8?B?THVrw6HFoSBDemVybmVy?= References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: How to get data from kernel module ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 May 2010 22:14:26 -0000 Luk=C3=A1=C5=A1 Czerner wrote: > Hi, >=20 > 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? >=20 > 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. >=20 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