Deleted Added
full compact
cdevmod.c (48275) cdevmod.c (66549)
1/* 08 Nov 1998*/
2/*
3 * cdevmod.c - a sample kld module implementing a character device driver.
4 *
5 * 08 Nov 1998 Rajesh Vaidheeswarran
6 *
7 * Copyright (c) 1998 Rajesh Vaidheeswarran
8 * All rights reserved.

--- 50 unchanged lines hidden (view full) ---

59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
1/* 08 Nov 1998*/
2/*
3 * cdevmod.c - a sample kld module implementing a character device driver.
4 *
5 * 08 Nov 1998 Rajesh Vaidheeswarran
6 *
7 * Copyright (c) 1998 Rajesh Vaidheeswarran
8 * All rights reserved.

--- 50 unchanged lines hidden (view full) ---

59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 *
68 * $FreeBSD: head/share/examples/kld/cdev/module/cdevmod.c 66549 2000-10-02 14:14:07Z sobomax $
67 */
68#include <sys/param.h>
69#include <sys/systm.h>
70#include <sys/kernel.h>
71#include <sys/module.h>
72#include <sys/conf.h>
73
74#include "cdev.h"
75
76#define CDEV_MAJOR 32
77
78static struct cdevsw my_devsw = {
79 /* open */ mydev_open,
80 /* close */ mydev_close,
69 */
70#include <sys/param.h>
71#include <sys/systm.h>
72#include <sys/kernel.h>
73#include <sys/module.h>
74#include <sys/conf.h>
75
76#include "cdev.h"
77
78#define CDEV_MAJOR 32
79
80static struct cdevsw my_devsw = {
81 /* open */ mydev_open,
82 /* close */ mydev_close,
81 /* read */ noread,
82 /* write */ nowrite,
83 /* read */ mydev_read,
84 /* write */ mydev_write,
83 /* ioctl */ mydev_ioctl,
85 /* ioctl */ mydev_ioctl,
84 /* stop */ nostop,
85 /* reset */ noreset,
86 /* devtotty */ nodevtotty,
87 /* poll */ nopoll,
88 /* mmap */ nommap,
89 /* strategy */ nostrategy,
90 /* name */ "cdev",
86 /* poll */ nopoll,
87 /* mmap */ nommap,
88 /* strategy */ nostrategy,
89 /* name */ "cdev",
91 /* parms */ noparms,
92 /* maj */ CDEV_MAJOR,
93 /* dump */ nodump,
94 /* psize */ nopsize,
95 /* flags */ D_TTY,
90 /* maj */ CDEV_MAJOR,
91 /* dump */ nodump,
92 /* psize */ nopsize,
93 /* flags */ D_TTY,
96 /* maxio */ 0,
97 /* bmaj */ -1
98};
99
94 /* bmaj */ -1
95};
96
97/*
98 * Used as the variable that is the reference to our device
99 * in devfs... we must keep this variable sane until we
100 * call kldunload.
101 */
102static dev_t sdev;
103
100/*
101 * This function is called each time the module is loaded or unloaded.
102 * Since we are a miscellaneous module, we have to provide whatever
103 * code is necessary to patch ourselves into the area we are being
104 * loaded to change.
105 *
106 * The stat information is basically common to all modules, so there
107 * is no real issue involved with stat; we will leave it lkm_nullcmd(),

--- 10 unchanged lines hidden (view full) ---

118
119 /* Do any initialization that you should do with the kernel */
120
121 /* if we make it to here, print copyright on console*/
122 printf("\nSample Loaded kld character device driver\n");
123 printf("Copyright (c) 1998\n");
124 printf("Rajesh Vaidheeswarran\n");
125 printf("All rights reserved\n");
104/*
105 * This function is called each time the module is loaded or unloaded.
106 * Since we are a miscellaneous module, we have to provide whatever
107 * code is necessary to patch ourselves into the area we are being
108 * loaded to change.
109 *
110 * The stat information is basically common to all modules, so there
111 * is no real issue involved with stat; we will leave it lkm_nullcmd(),

--- 10 unchanged lines hidden (view full) ---

122
123 /* Do any initialization that you should do with the kernel */
124
125 /* if we make it to here, print copyright on console*/
126 printf("\nSample Loaded kld character device driver\n");
127 printf("Copyright (c) 1998\n");
128 printf("Rajesh Vaidheeswarran\n");
129 printf("All rights reserved\n");
130 sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev");
126 break; /* Success*/
127
128 case MOD_UNLOAD:
129 printf("Unloaded kld character device driver\n");
131 break; /* Success*/
132
133 case MOD_UNLOAD:
134 printf("Unloaded kld character device driver\n");
135 destroy_dev(sdev);
130 break; /* Success*/
131
132 default: /* we only understand load/unload*/
133 err = EINVAL;
134 break;
135 }
136
137 return(err);
138}
139
140/* Now declare the module to the system */
141
136 break; /* Success*/
137
138 default: /* we only understand load/unload*/
139 err = EINVAL;
140 break;
141 }
142
143 return(err);
144}
145
146/* Now declare the module to the system */
147
142DEV_MODULE(cdev, CDEV_MAJOR, -1, my_devsw, cdev_load, 0);
148DEV_MODULE(cdev, cdev_load, NULL);