186d7f5d3SJohn Marino# Copyright (c) 1998 Rajesh Vaidheeswarran 286d7f5d3SJohn Marino# All rights reserved. 386d7f5d3SJohn Marino# 486d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without 586d7f5d3SJohn Marino# modification, are permitted provided that the following conditions 686d7f5d3SJohn Marino# are met: 786d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright 886d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer. 986d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright 1086d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer in the 1186d7f5d3SJohn Marino# documentation and/or other materials provided with the distribution. 1286d7f5d3SJohn Marino# 3. All advertising materials mentioning features or use of this software 1386d7f5d3SJohn Marino# must display the following acknowledgement: 1486d7f5d3SJohn Marino# This product includes software developed by Rajesh Vaidheeswarran 1586d7f5d3SJohn Marino# 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote 1686d7f5d3SJohn Marino# products derived from this software without specific prior written 1786d7f5d3SJohn Marino# permission. 1886d7f5d3SJohn Marino# 1986d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``AS IS'' AND ANY 2086d7f5d3SJohn Marino# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2186d7f5d3SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2286d7f5d3SJohn Marino# ARE DISCLAIMED. IN NO EVENT SHALL THE RAJESH VAIDHEESWARRAN BE LIABLE 2386d7f5d3SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2486d7f5d3SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2586d7f5d3SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2686d7f5d3SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2786d7f5d3SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2886d7f5d3SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2986d7f5d3SJohn Marino# SUCH DAMAGE. 3086d7f5d3SJohn Marino# 3186d7f5d3SJohn Marino# Copyright (c) 1993 Terrence R. Lambert. 3286d7f5d3SJohn Marino# All rights reserved. 3386d7f5d3SJohn Marino# 3486d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without 3586d7f5d3SJohn Marino# modification, are permitted provided that the following conditions 3686d7f5d3SJohn Marino# are met: 3786d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright 3886d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer. 3986d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright 4086d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer in the 4186d7f5d3SJohn Marino# documentation and/or other materials provided with the distribution. 4286d7f5d3SJohn Marino# 3. All advertising materials mentioning features or use of this software 4386d7f5d3SJohn Marino# must display the following acknowledgement: 4486d7f5d3SJohn Marino# This product includes software developed by Terrence R. Lambert. 4586d7f5d3SJohn Marino# 4. The name Terrence R. Lambert may not be used to endorse or promote 4686d7f5d3SJohn Marino# products derived from this software without specific prior written 4786d7f5d3SJohn Marino# permission. 4886d7f5d3SJohn Marino# 4986d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY 5086d7f5d3SJohn Marino# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5186d7f5d3SJohn Marino# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5286d7f5d3SJohn Marino# ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE 5386d7f5d3SJohn Marino# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5486d7f5d3SJohn Marino# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5586d7f5d3SJohn Marino# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5686d7f5d3SJohn Marino# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5786d7f5d3SJohn Marino# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5886d7f5d3SJohn Marino# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5986d7f5d3SJohn Marino# SUCH DAMAGE. 6086d7f5d3SJohn Marino# 6186d7f5d3SJohn Marino# $FreeBSD: src/share/examples/kld/cdev/README,v 1.1.6.1 2000/10/25 09:02:33 sobomax Exp $ 6286d7f5d3SJohn Marino# $DragonFly: src/share/examples/kld/cdev/README,v 1.2 2003/06/17 04:36:57 dillon Exp $ 6386d7f5d3SJohn Marino# 6486d7f5d3SJohn Marino 6586d7f5d3SJohn Marino1.0 Overview 6686d7f5d3SJohn Marino 6786d7f5d3SJohn Marino This is the README file for the sample kld module 6886d7f5d3SJohn Marino that mimics a character device driver. 6986d7f5d3SJohn Marino 7086d7f5d3SJohn Marino A kld module may be used to load any data or 7186d7f5d3SJohn Marino program into the kernel that can be made available by 7286d7f5d3SJohn Marino modifying a table, pointer, or other kernel data to inform 7386d7f5d3SJohn Marino the kernel that the module should be used instead of the 7486d7f5d3SJohn Marino previous code/data path. 7586d7f5d3SJohn Marino 7686d7f5d3SJohn Marino Generally, it is assumed that a loadable module is one of 7786d7f5d3SJohn Marino a set of similar modules (such as a file system or console 7886d7f5d3SJohn Marino terminal emulation), and that the reference is through a 7986d7f5d3SJohn Marino table (such as vfssw[]), and that a "special" value is 8086d7f5d3SJohn Marino assigned to the slots which are allowed to be replaced. 8186d7f5d3SJohn Marino This is not enforced, so you may use the kld module 8286d7f5d3SJohn Marino any way you see fit. 8386d7f5d3SJohn Marino 8486d7f5d3SJohn Marino As with the loadable system calls, it may be desirable to 8586d7f5d3SJohn Marino allow the module loader to replace an *existing* entry to 8686d7f5d3SJohn Marino try out changes to kernel code without rebuilding and 8786d7f5d3SJohn Marino booting from the new kernel. 8886d7f5d3SJohn Marino 8986d7f5d3SJohn Marino The idea behind this example is to show some interaction 9086d7f5d3SJohn Marino with the device driver. Therefore the flow of the code that 9186d7f5d3SJohn Marino this driver is aimed at is as follows: 9286d7f5d3SJohn Marino 9386d7f5d3SJohn Marino open(2) -> ioctl(2) -> write(2) -> read(2) -> close(2). 9486d7f5d3SJohn Marino 9586d7f5d3SJohn Marino We will first open the device in the /dev/ directory; then 9686d7f5d3SJohn Marino we will send an ioctl message to it using ioctl(2) call; 9786d7f5d3SJohn Marino then write a small string via the write(2) call. This string 9886d7f5d3SJohn Marino we write to the device will be stored in a static buffer, 9986d7f5d3SJohn Marino and later will be accessible via the read(2) call. Finally, 10086d7f5d3SJohn Marino we will close(2) our open()'d device so that we may no 10186d7f5d3SJohn Marino longer make read or write calls on it. 10286d7f5d3SJohn Marino 10386d7f5d3SJohn Marino2.0 Directions 10486d7f5d3SJohn Marino 10586d7f5d3SJohn Marino To test the module, do the following: 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marino cd module 10886d7f5d3SJohn Marino make load 10986d7f5d3SJohn Marino 11086d7f5d3SJohn Marino A load message (the copyright) will be printed on the console. 11186d7f5d3SJohn Marino 11286d7f5d3SJohn Marino cd ../test 11386d7f5d3SJohn Marino make load 11486d7f5d3SJohn Marino 11586d7f5d3SJohn Marino The system call prints a message on the console when called. 11686d7f5d3SJohn Marino This message will be printed when running "make load" in 11786d7f5d3SJohn Marino the "test" subdirectory. 11886d7f5d3SJohn Marino 11986d7f5d3SJohn Marino 12086d7f5d3SJohn Marino3.0 Recovering resources 12186d7f5d3SJohn Marino 12286d7f5d3SJohn Marino The module consumes memory when loaded; it can be freed up by 12386d7f5d3SJohn Marino unloading it. To unload it, type the following from the directory 12486d7f5d3SJohn Marino this file is in: 12586d7f5d3SJohn Marino 12686d7f5d3SJohn Marino cd module 12786d7f5d3SJohn Marino make unload 12886d7f5d3SJohn Marino 12986d7f5d3SJohn Marino The miscellaneous module will be unloaded by name. 13086d7f5d3SJohn Marino 13186d7f5d3SJohn Marino 13286d7f5d3SJohn Marino4.0 END OF DOCUMENT 133