Date: Sun, 15 Feb 2015 11:43:51 +0700 From: dmaryanto@gmail.com To: Ryan Stone <rysto32@gmail.com>, Yue Chen <ycyc321@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Suggestions for communication between FreeBSD user-space and kernel modules Message-ID: <20150215044351.5988497.50786.18252@gmail.com> In-Reply-To: <CAFMmRNw9rYWOx%2BX8sAh2oXUbgjkRhQMiKK8JnPTft9rAay1K_w@mail.gmail.com> References: <CAKtBrB47mCeTCFjrHpVww0LXJupDq_zYOy_z78pM8AV0U6hUkw@mail.gmail.com> <CAFMmRNw9rYWOx%2BX8sAh2oXUbgjkRhQMiKK8JnPTft9rAay1K_w@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
---- tail -f /var/log/travel.log http://arungi.selatsunda.co.id =A0 Original Message =A0 From: Ryan Stone Sent: Minggu, 15 Februari 2015 09.54 To: Yue Chen Cc: freebsd-hackers@freebsd.org Subject: Re: Suggestions for communication between FreeBSD user-space and k= ernel modules The two main interfaces for passing data between userland and the kernel in FreeBSD are syctls and ioctls (there are others but their use is rather specialized). sysctls are typically the simplest to set up, but aren't well suited for passing around complex structured data. sysctls are very easy to read and write from the command line, though, so they're popular for exposing individual tuning parameters. The kernel interfaces for creating sysctls are documented here: https://www.freebsd.org/cgi/man.cgi?query=3Dsysctl&apropos=3D0&sektion=3D9&= manpath=3DFreeBSD+10.1-RELEASE&arch=3Ddefault&format=3Dhtml https://www.freebsd.org/cgi/man.cgi?query=3Dsysctl_add_oid&apropos=3D0&sekt= ion=3D0&manpath=3DFreeBSD+10.1-RELEASE&arch=3Ddefault&format=3Dhtml ioctls are a little more complicated to use, but are more flexible in what kind of data they can accept. The man pages for this aren't as good, but the basic steps are: 1) Create a device node in /dev by calling make_dev() (https://www.freebsd.org/cgi/man.cgi?query=3Dmake_dev&apropos=3D0&sektion= =3D0&manpath=3DFreeBSD+10.1-RELEASE&arch=3Ddefault&format=3Dhtml) 2) In your userland application, call open(2) to get a file descriptor and then ioctl(2) on the file descriptor to pass data to/from the kernel 2) In the cdevsw structure, implement the ioctl method. This method will be called when the userland application calls ioctl(2) 3) The request argument using the macros in <sys/ioccom.h>. _IOW is for ioctls that send data from userland to the kernel, _IOR is for ioctls that fetch data from the kernel and _IOWR is for ioctls that both send data from userland to the kernel and fetch data back in a single call. Try to use unique values for your ioctls requests. Some of the other possible methods include include mmap, which can be used to create shared memory between the kernel and userland; netgraph, which is networking-focused interface; and sockets, which can be a tricky interface to use correctly in the kernel. _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150215044351.5988497.50786.18252>