1158722Sflz# Copyright (c) 1998 Rajesh Vaidheeswarran 2158722Sflz# All rights reserved. 3158722Sflz# 4158722Sflz# Redistribution and use in source and binary forms, with or without 5158722Sflz# modification, are permitted provided that the following conditions 6158722Sflz# are met: 7158722Sflz# 1. Redistributions of source code must retain the above copyright 8158722Sflz# notice, this list of conditions and the following disclaimer. 9158722Sflz# 2. Redistributions in binary form must reproduce the above copyright 10158722Sflz# notice, this list of conditions and the following disclaimer in the 11158722Sflz# documentation and/or other materials provided with the distribution. 12158722Sflz# 3. All advertising materials mentioning features or use of this software 13158722Sflz# must display the following acknowledgement: 14158722Sflz# This product includes software developed by Rajesh Vaidheeswarran 15158722Sflz# 4. The name Rajesh Vaidheeswarran may not be used to endorse or promote 16158722Sflz# products derived from this software without specific prior written 17158722Sflz# permission. 18158722Sflz# 19158722Sflz# THIS SOFTWARE IS PROVIDED BY RAJESH VAIDHEESWARRAN ``AS IS'' AND ANY 20158722Sflz# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21158722Sflz# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22158722Sflz# ARE DISCLAIMED. IN NO EVENT SHALL THE RAJESH VAIDHEESWARRAN BE LIABLE 23158722Sflz# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24158722Sflz# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25158722Sflz# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26158722Sflz# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27158722Sflz# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28158722Sflz# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29158722Sflz# SUCH DAMAGE. 30158722Sflz# 31158722Sflz# Copyright (c) 1993 Terrence R. Lambert. 32158722Sflz# All rights reserved. 33158722Sflz# 34158722Sflz# Redistribution and use in source and binary forms, with or without 35158722Sflz# modification, are permitted provided that the following conditions 36158722Sflz# are met: 37158722Sflz# 1. Redistributions of source code must retain the above copyright 38158722Sflz# notice, this list of conditions and the following disclaimer. 39165683Syar# 2. Redistributions in binary form must reproduce the above copyright 40165683Syar# notice, this list of conditions and the following disclaimer in the 41158722Sflz# documentation and/or other materials provided with the distribution. 42158722Sflz# 3. All advertising materials mentioning features or use of this software 43158722Sflz# must display the following acknowledgement: 44158722Sflz# This product includes software developed by Terrence R. Lambert. 45158722Sflz# 4. The name Terrence R. Lambert may not be used to endorse or promote 46158722Sflz# products derived from this software without specific prior written 47158722Sflz# permission. 48158722Sflz# 49158722Sflz# THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY 50158722Sflz# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51158722Sflz# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52158722Sflz# ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE 53158722Sflz# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54158722Sflz# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55158722Sflz# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56158722Sflz# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57158722Sflz# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58158722Sflz# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59158722Sflz# SUCH DAMAGE. 60158722Sflz# 61158722Sflz# $FreeBSD: releng/10.3/share/examples/kld/cdev/README 66549 2000-10-02 14:14:07Z sobomax $ 62158722Sflz# 63158722Sflz 64158722Sflz1.0 Overview 65158722Sflz 66158722Sflz This is the README file for the sample kld module 67158722Sflz that mimics a character device driver. 68158722Sflz 69158722Sflz A kld module may be used to load any data or 70158722Sflz program into the kernel that can be made available by 71158722Sflz modifying a table, pointer, or other kernel data to inform 72158722Sflz the kernel that the module should be used instead of the 73158722Sflz previous code/data path. 74158722Sflz 75158722Sflz Generally, it is assumed that a loadable module is one of 76158722Sflz a set of similar modules (such as a file system or console 77158722Sflz terminal emulation), and that the reference is through a 78158722Sflz table (such as vfssw[]), and that a "special" value is 79158722Sflz assigned to the slots which are allowed to be replaced. 80158722Sflz This is not enforced, so you may use the kld module 81158722Sflz any way you see fit. 82158722Sflz 83158722Sflz As with the loadable system calls, it may be desirable to 84158722Sflz allow the module loader to replace an *existing* entry to 85158722Sflz try out changes to kernel code without rebuilding and 86158722Sflz booting from the new kernel. 87158722Sflz 88158722Sflz The idea behind this example is to show some interaction 89158722Sflz with the device driver. Therefore the flow of the code that 90158722Sflz this driver is aimed at is as follows: 91158722Sflz 92158722Sflz open(2) -> ioctl(2) -> write(2) -> read(2) -> close(2). 93158722Sflz 94158722Sflz We will first open the device in the /dev/ directory; then 95158722Sflz we will send an ioctl message to it using ioctl(2) call; 96158722Sflz then write a small string via the write(2) call. This string 97158722Sflz we write to the device will be stored in a static buffer, 98158722Sflz and later will be accessible via the read(2) call. Finally, 99158722Sflz we will close(2) our open()'d device so that we may no 100158722Sflz longer make read or write calls on it. 101158722Sflz 102158722Sflz2.0 Directions 103158722Sflz 104158722Sflz To test the module, do the following: 105158722Sflz 106158722Sflz cd module 107158722Sflz make load 108158722Sflz 109158722Sflz A load message (the copyright) will be printed on the console. 110158722Sflz 111158722Sflz cd ../test 112158722Sflz make load 113158722Sflz 114158722Sflz The system call prints a message on the console when called. 115158722Sflz This message will be printed when running "make load" in 116165683Syar the "test" subdirectory. 117165683Syar 118165683Syar 119158722Sflz3.0 Recovering resources 120158722Sflz 121158722Sflz The module consumes memory when loaded; it can be freed up by 122158722Sflz unloading it. To unload it, type the following from the directory 123158722Sflz this file is in: 124158722Sflz 125158722Sflz cd module 126158722Sflz make unload 127158722Sflz 128158722Sflz The miscellaneous module will be unloaded by name. 129158722Sflz 130158722Sflz 131158722Sflz4.0 END OF DOCUMENT 132158722Sflz