kernel - Remove D_KQFILTER flag
[dragonfly.git] / sys / dev / misc / snp / snp.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1995 Ugen J.S.Antsilevich
3 *
4 * Redistribution and use in source forms, with and without modification,
5 * are permitted provided that this entire comment appears intact.
6 *
7 * Redistribution in binary form may occur without any restrictions.
8 * Obviously, it would be nice if you gave credit where credit is due
9 * but requiring it would be too onerous.
10 *
11 * This software is provided ``AS IS'' without any warranties of any kind.
12 *
13 * Snoop stuff.
14 *
15 * $FreeBSD: src/sys/dev/snp/snp.c,v 1.69.2.2 2002/05/06 07:30:02 dd Exp $
028066b1 16 * $DragonFly: src/sys/dev/misc/snp/snp.c,v 1.19 2007/05/08 02:31:41 dillon Exp $
984263bc
MD
17 */
18
95db3aac 19#include "use_snp.h"
984263bc
MD
20#include <sys/param.h>
21#include <sys/systm.h>
22#include <sys/filio.h>
23#include <sys/malloc.h>
24#include <sys/tty.h>
25#include <sys/conf.h>
5d7a9a94 26#include <sys/event.h>
984263bc
MD
27#include <sys/kernel.h>
28#include <sys/queue.h>
29#include <sys/snoop.h>
12cc2857 30#include <sys/thread2.h>
984263bc 31#include <sys/vnode.h>
f15db79e 32#include <sys/device.h>
2c1e28dd 33#include <sys/devfs.h>
984263bc
MD
34
35static l_close_t snplclose;
36static l_write_t snplwrite;
37static d_open_t snpopen;
38static d_close_t snpclose;
39static d_read_t snpread;
40static d_write_t snpwrite;
41static d_ioctl_t snpioctl;
5d7a9a94 42static d_kqfilter_t snpkqfilter;
8be7edad
MD
43static d_clone_t snpclone;
44DEVFS_DECLARE_CLONE_BITMAP(snp);
95db3aac 45
5d7a9a94 46static void snpfilter_detach(struct knote *);
163625b9
SG
47static int snpfilter_rd(struct knote *, long);
48static int snpfilter_wr(struct knote *, long);
5d7a9a94 49
95db3aac 50#if NSNP <= 1
8be7edad 51#define SNP_PREALLOCATED_UNITS 4
95db3aac
AH
52#else
53#define SNP_PREALLOCATED_UNITS NSNP
54#endif
984263bc
MD
55
56#define CDEV_MAJOR 53
fef8985e 57static struct dev_ops snp_ops = {
d4b8aec4 58 { "snp", CDEV_MAJOR, 0 },
fef8985e
MD
59 .d_open = snpopen,
60 .d_close = snpclose,
61 .d_read = snpread,
62 .d_write = snpwrite,
63 .d_ioctl = snpioctl,
5d7a9a94 64 .d_kqfilter = snpkqfilter
984263bc
MD
65};
66
67static struct linesw snpdisc = {
68 ttyopen, snplclose, ttread, snplwrite,
69 l_nullioctl, ttyinput, ttstart, ttymodem
70};
71
72/*
73 * This is the main snoop per-device structure.
74 */
75struct snoop {
76 LIST_ENTRY(snoop) snp_list; /* List glue. */
b13267a5 77 cdev_t snp_target; /* Target tty device. */
984263bc
MD
78 struct tty *snp_tty; /* Target tty pointer. */
79 u_long snp_len; /* Possible length. */
80 u_long snp_base; /* Data base. */
81 u_long snp_blen; /* Used length. */
82 caddr_t snp_buf; /* Allocation pointer. */
83 int snp_flags; /* Flags. */
5b22f1a7 84 struct kqinfo snp_kq; /* Kqueue info. */
984263bc
MD
85 int snp_olddisc; /* Old line discipline. */
86};
87
88/*
89 * Possible flags.
90 */
91#define SNOOP_ASYNC 0x0002
92#define SNOOP_OPEN 0x0004
93#define SNOOP_RWAIT 0x0008
94#define SNOOP_OFLOW 0x0010
95#define SNOOP_DOWN 0x0020
96
97/*
98 * Other constants.
99 */
100#define SNOOP_MINLEN (4*1024) /* This should be power of 2.
101 * 4K tested to be the minimum
102 * for which on normal tty
103 * usage there is no need to
104 * allocate more.
105 */
106#define SNOOP_MAXLEN (64*1024) /* This one also,64K enough
107 * If we grow more,something
108 * really bad in this world..
109 */
110
111static MALLOC_DEFINE(M_SNP, "snp", "Snoop device data");
112/*
113 * The number of the "snoop" line discipline. This gets determined at
114 * module load time.
115 */
116static int snooplinedisc;
117
118
119static LIST_HEAD(, snoop) snp_sclist = LIST_HEAD_INITIALIZER(&snp_sclist);
120
b13267a5 121static struct tty *snpdevtotty (cdev_t dev);
38e94a25
RG
122static int snp_detach (struct snoop *snp);
123static int snp_down (struct snoop *snp);
124static int snp_in (struct snoop *snp, char *buf, int n);
125static int snp_modevent (module_t mod, int what, void *arg);
984263bc
MD
126
127static int
c436375a 128snplclose(struct tty *tp, int flag)
984263bc
MD
129{
130 struct snoop *snp;
131 int error;
132
133 snp = tp->t_sc;
134 error = snp_down(snp);
135 if (error != 0)
136 return (error);
137 error = ttylclose(tp, flag);
138 return (error);
139}
140
141static int
c436375a 142snplwrite(struct tty *tp, struct uio *uio, int flag)
984263bc
MD
143{
144 struct iovec iov;
145 struct uio uio2;
146 struct snoop *snp;
147 int error, ilen;
148 char *ibuf;
149
150 error = 0;
151 ibuf = NULL;
152 snp = tp->t_sc;
153 while (uio->uio_resid > 0) {
e54488bb 154 ilen = (int)szmin(512, uio->uio_resid);
efda3bd0 155 ibuf = kmalloc(ilen, M_SNP, M_WAITOK);
e54488bb 156 error = uiomove(ibuf, (size_t)ilen, uio);
984263bc
MD
157 if (error != 0)
158 break;
159 snp_in(snp, ibuf, ilen);
160 /* Hackish, but probably the least of all evils. */
161 iov.iov_base = ibuf;
162 iov.iov_len = ilen;
163 uio2.uio_iov = &iov;
164 uio2.uio_iovcnt = 1;
165 uio2.uio_offset = 0;
166 uio2.uio_resid = ilen;
167 uio2.uio_segflg = UIO_SYSSPACE;
168 uio2.uio_rw = UIO_WRITE;
dadab5e9 169 uio2.uio_td = uio->uio_td;
984263bc
MD
170 error = ttwrite(tp, &uio2, flag);
171 if (error != 0)
172 break;
efda3bd0 173 kfree(ibuf, M_SNP);
984263bc
MD
174 ibuf = NULL;
175 }
176 if (ibuf != NULL)
efda3bd0 177 kfree(ibuf, M_SNP);
984263bc
MD
178 return (error);
179}
180
181static struct tty *
b13267a5 182snpdevtotty(cdev_t dev)
984263bc 183{
f15db79e 184 if ((dev_dflags(dev) & D_TTY) == 0)
984263bc
MD
185 return (NULL);
186 return (dev->si_tty);
187}
188
189#define SNP_INPUT_BUF 5 /* This is even too much, the maximal
190 * interactive mode write is 3 bytes
191 * length for function keys...
192 */
193
194static int
fef8985e 195snpwrite(struct dev_write_args *ap)
984263bc 196{
b13267a5 197 cdev_t dev = ap->a_head.a_dev;
fef8985e 198 struct uio *uio = ap->a_uio;
984263bc
MD
199 struct snoop *snp;
200 struct tty *tp;
201 int error, i, len;
202 unsigned char c[SNP_INPUT_BUF];
203
204 snp = dev->si_drv1;
205 tp = snp->snp_tty;
206 if (tp == NULL)
207 return (EIO);
208 if ((tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
209 tp->t_line == snooplinedisc)
210 goto tty_input;
211
e3869ec7 212 kprintf("Snoop: attempt to write to bad tty.\n");
984263bc
MD
213 return (EIO);
214
215tty_input:
216 if (!(tp->t_state & TS_ISOPEN))
217 return (EIO);
218
219 while (uio->uio_resid > 0) {
e54488bb
MD
220 len = (int)szmin(uio->uio_resid, SNP_INPUT_BUF);
221 if ((error = uiomove(c, (size_t)len, uio)) != 0)
984263bc
MD
222 return (error);
223 for (i=0; i < len; i++) {
224 if (ttyinput(c[i], tp))
225 return (EIO);
226 }
227 }
228 return (0);
229}
230
231
232static int
fef8985e 233snpread(struct dev_read_args *ap)
984263bc 234{
b13267a5 235 cdev_t dev = ap->a_head.a_dev;
fef8985e 236 struct uio *uio = ap->a_uio;
984263bc 237 struct snoop *snp;
12cc2857 238 int error, len, n, nblen;
984263bc
MD
239 caddr_t from;
240 char *nbuf;
241
242 snp = dev->si_drv1;
243 KASSERT(snp->snp_len + snp->snp_base <= snp->snp_blen,
244 ("snoop buffer error"));
245
246 if (snp->snp_tty == NULL)
247 return (EIO);
248
249 snp->snp_flags &= ~SNOOP_RWAIT;
250
251 do {
252 if (snp->snp_len == 0) {
fef8985e 253 if (ap->a_ioflag & IO_NDELAY)
984263bc
MD
254 return (EWOULDBLOCK);
255 snp->snp_flags |= SNOOP_RWAIT;
377d4740 256 error = tsleep((caddr_t)snp, PCATCH, "snprd", 0);
984263bc
MD
257 if (error != 0)
258 return (error);
259 }
260 } while (snp->snp_len == 0);
261
262 n = snp->snp_len;
263
264 error = 0;
265 while (snp->snp_len > 0 && uio->uio_resid > 0 && error == 0) {
e54488bb 266 len = (int)szmin(uio->uio_resid, snp->snp_len);
984263bc
MD
267 from = (caddr_t)(snp->snp_buf + snp->snp_base);
268 if (len == 0)
269 break;
270
e54488bb 271 error = uiomove(from, (size_t)len, uio);
984263bc
MD
272 snp->snp_base += len;
273 snp->snp_len -= len;
274 }
275 if ((snp->snp_flags & SNOOP_OFLOW) && (n < snp->snp_len)) {
276 snp->snp_flags &= ~SNOOP_OFLOW;
277 }
12cc2857 278 crit_enter();
984263bc
MD
279 nblen = snp->snp_blen;
280 if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) {
281 while (nblen / 2 >= snp->snp_len && nblen / 2 >= SNOOP_MINLEN)
282 nblen = nblen / 2;
efda3bd0 283 if ((nbuf = kmalloc(nblen, M_SNP, M_NOWAIT)) != NULL) {
984263bc 284 bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
efda3bd0 285 kfree(snp->snp_buf, M_SNP);
984263bc
MD
286 snp->snp_buf = nbuf;
287 snp->snp_blen = nblen;
288 snp->snp_base = 0;
289 }
290 }
12cc2857 291 crit_exit();
984263bc
MD
292
293 return (error);
294}
295
296static int
c436375a 297snp_in(struct snoop *snp, char *buf, int n)
984263bc
MD
298{
299 int s_free, s_tail;
12cc2857 300 int len, nblen;
984263bc
MD
301 caddr_t from, to;
302 char *nbuf;
303
304 KASSERT(n >= 0, ("negative snoop char count"));
305
306 if (n == 0)
307 return (0);
308
309 if (snp->snp_flags & SNOOP_DOWN) {
e3869ec7 310 kprintf("Snoop: more data to down interface.\n");
984263bc
MD
311 return (0);
312 }
313
314 if (snp->snp_flags & SNOOP_OFLOW) {
e3869ec7 315 kprintf("Snoop: buffer overflow.\n");
984263bc
MD
316 /*
317 * On overflow we just repeat the standart close
318 * procedure...yes , this is waste of space but.. Then next
319 * read from device will fail if one would recall he is
320 * snooping and retry...
321 */
322
323 return (snp_down(snp));
324 }
325 s_tail = snp->snp_blen - (snp->snp_len + snp->snp_base);
326 s_free = snp->snp_blen - snp->snp_len;
327
328
329 if (n > s_free) {
12cc2857 330 crit_enter();
984263bc
MD
331 nblen = snp->snp_blen;
332 while ((n > s_free) && ((nblen * 2) <= SNOOP_MAXLEN)) {
333 nblen = snp->snp_blen * 2;
334 s_free = nblen - (snp->snp_len + snp->snp_base);
335 }
efda3bd0 336 if ((n <= s_free) && (nbuf = kmalloc(nblen, M_SNP, M_NOWAIT))) {
984263bc 337 bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
efda3bd0 338 kfree(snp->snp_buf, M_SNP);
984263bc
MD
339 snp->snp_buf = nbuf;
340 snp->snp_blen = nblen;
341 snp->snp_base = 0;
342 } else {
343 snp->snp_flags |= SNOOP_OFLOW;
344 if (snp->snp_flags & SNOOP_RWAIT) {
345 snp->snp_flags &= ~SNOOP_RWAIT;
346 wakeup((caddr_t)snp);
347 }
12cc2857 348 crit_exit();
984263bc
MD
349 return (0);
350 }
12cc2857 351 crit_exit();
984263bc
MD
352 }
353 if (n > s_tail) {
354 from = (caddr_t)(snp->snp_buf + snp->snp_base);
355 to = (caddr_t)(snp->snp_buf);
356 len = snp->snp_len;
357 bcopy(from, to, len);
358 snp->snp_base = 0;
359 }
360 to = (caddr_t)(snp->snp_buf + snp->snp_base + snp->snp_len);
361 bcopy(buf, to, n);
362 snp->snp_len += n;
363
364 if (snp->snp_flags & SNOOP_RWAIT) {
365 snp->snp_flags &= ~SNOOP_RWAIT;
366 wakeup((caddr_t)snp);
367 }
5b22f1a7 368 KNOTE(&snp->snp_kq.ki_note, 0);
984263bc
MD
369
370 return (n);
371}
372
373static int
fef8985e 374snpopen(struct dev_open_args *ap)
984263bc 375{
b13267a5 376 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
377 struct snoop *snp;
378
379 if (dev->si_drv1 == NULL) {
8be7edad 380#if 0
fef8985e 381 make_dev(&snp_ops, minor(dev), UID_ROOT, GID_WHEEL,
984263bc 382 0600, "snp%d", minor(dev));
8be7edad 383#endif
efda3bd0 384 dev->si_drv1 = snp = kmalloc(sizeof(*snp), M_SNP,
984263bc 385 M_WAITOK | M_ZERO);
e4c9c0c8 386 } else {
984263bc 387 return (EBUSY);
e4c9c0c8 388 }
984263bc
MD
389
390 /*
391 * We intentionally do not OR flags with SNOOP_OPEN, but set them so
392 * all previous settings (especially SNOOP_OFLOW) will be cleared.
393 */
394 snp->snp_flags = SNOOP_OPEN;
395
efda3bd0 396 snp->snp_buf = kmalloc(SNOOP_MINLEN, M_SNP, M_WAITOK);
984263bc
MD
397 snp->snp_blen = SNOOP_MINLEN;
398 snp->snp_base = 0;
399 snp->snp_len = 0;
400
401 /*
402 * snp_tty == NULL is for inactive snoop devices.
403 */
404 snp->snp_tty = NULL;
028066b1 405 snp->snp_target = NULL;
984263bc
MD
406
407 LIST_INSERT_HEAD(&snp_sclist, snp, snp_list);
408 return (0);
409}
410
411
412static int
c436375a 413snp_detach(struct snoop *snp)
984263bc
MD
414{
415 struct tty *tp;
416
417 snp->snp_base = 0;
418 snp->snp_len = 0;
419
420 /*
421 * If line disc. changed we do not touch this pointer, SLIP/PPP will
422 * change it anyway.
423 */
424 tp = snp->snp_tty;
425 if (tp == NULL)
426 goto detach_notty;
427
428 if (tp && (tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
429 tp->t_line == snooplinedisc) {
430 tp->t_sc = NULL;
431 tp->t_state &= ~TS_SNOOP;
432 tp->t_line = snp->snp_olddisc;
433 } else
e3869ec7 434 kprintf("Snoop: bad attached tty data.\n");
984263bc
MD
435
436 snp->snp_tty = NULL;
028066b1 437 snp->snp_target = NULL;
984263bc
MD
438
439detach_notty:
5b22f1a7 440 KNOTE(&snp->snp_kq.ki_note, 0);
984263bc 441 if ((snp->snp_flags & SNOOP_OPEN) == 0)
efda3bd0 442 kfree(snp, M_SNP);
984263bc
MD
443
444 return (0);
445}
446
447static int
fef8985e 448snpclose(struct dev_close_args *ap)
984263bc 449{
b13267a5 450 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
451 struct snoop *snp;
452
453 snp = dev->si_drv1;
454 snp->snp_blen = 0;
455 LIST_REMOVE(snp, snp_list);
efda3bd0 456 kfree(snp->snp_buf, M_SNP);
984263bc
MD
457 snp->snp_flags &= ~SNOOP_OPEN;
458 dev->si_drv1 = NULL;
8be7edad
MD
459 if (dev->si_uminor >= SNP_PREALLOCATED_UNITS) {
460 devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(snp), dev->si_uminor);
461 destroy_dev(dev);
462 }
984263bc
MD
463 return (snp_detach(snp));
464}
465
466static int
c436375a 467snp_down(struct snoop *snp)
984263bc
MD
468{
469
470 if (snp->snp_blen != SNOOP_MINLEN) {
efda3bd0
MD
471 kfree(snp->snp_buf, M_SNP);
472 snp->snp_buf = kmalloc(SNOOP_MINLEN, M_SNP, M_WAITOK);
984263bc
MD
473 snp->snp_blen = SNOOP_MINLEN;
474 }
475 snp->snp_flags |= SNOOP_DOWN;
476
477 return (snp_detach(snp));
478}
479
480static int
fef8985e 481snpioctl(struct dev_ioctl_args *ap)
984263bc 482{
b13267a5 483 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
484 struct snoop *snp;
485 struct tty *tp, *tpo;
b13267a5 486 cdev_t tdev;
984263bc
MD
487
488 snp = dev->si_drv1;
fef8985e 489 switch (ap->a_cmd) {
984263bc 490 case SNPSTTY:
fef8985e 491 tdev = udev2dev(*((udev_t *)ap->a_data), 0);
028066b1 492 if (tdev == NULL)
984263bc
MD
493 return (snp_down(snp));
494
495 tp = snpdevtotty(tdev);
496 if (!tp)
497 return (EINVAL);
498 if (tp->t_state & TS_SNOOP)
499 return (EBUSY);
500
12cc2857 501 crit_enter();
984263bc 502
028066b1 503 if (snp->snp_target == NULL) {
984263bc
MD
504 tpo = snp->snp_tty;
505 if (tpo)
506 tpo->t_state &= ~TS_SNOOP;
507 }
508
509 tp->t_sc = (caddr_t)snp;
510 tp->t_state |= TS_SNOOP;
511 snp->snp_olddisc = tp->t_line;
512 tp->t_line = snooplinedisc;
513 snp->snp_tty = tp;
514 snp->snp_target = tdev;
515
516 /*
517 * Clean overflow and down flags -
518 * we'll have a chance to get them in the future :)))
519 */
520 snp->snp_flags &= ~SNOOP_OFLOW;
521 snp->snp_flags &= ~SNOOP_DOWN;
12cc2857 522 crit_exit();
984263bc
MD
523 break;
524
525 case SNPGTTY:
526 /*
527 * We keep snp_target field specially to make
528 * SNPGTTY happy, else we can't know what is device
529 * major/minor for tty.
530 */
b13267a5 531 *((cdev_t *)ap->a_data) = snp->snp_target;
984263bc
MD
532 break;
533
984263bc 534 case FIOASYNC:
fef8985e 535 if (*(int *)ap->a_data)
984263bc
MD
536 snp->snp_flags |= SNOOP_ASYNC;
537 else
538 snp->snp_flags &= ~SNOOP_ASYNC;
539 break;
540
541 case FIONREAD:
12cc2857 542 crit_enter();
984263bc 543 if (snp->snp_tty != NULL)
fef8985e 544 *(int *)ap->a_data = snp->snp_len;
984263bc
MD
545 else
546 if (snp->snp_flags & SNOOP_DOWN) {
547 if (snp->snp_flags & SNOOP_OFLOW)
fef8985e 548 *(int *)ap->a_data = SNP_OFLOW;
984263bc 549 else
fef8985e 550 *(int *)ap->a_data = SNP_TTYCLOSE;
984263bc 551 } else {
fef8985e 552 *(int *)ap->a_data = SNP_DETACH;
984263bc 553 }
12cc2857 554 crit_exit();
984263bc
MD
555 break;
556
557 default:
558 return (ENOTTY);
559 }
560 return (0);
561}
562
163625b9 563static struct filterops snpfiltops_rd =
4c91dbc9 564 { FILTEROP_ISFD, NULL, snpfilter_detach, snpfilter_rd };
163625b9 565static struct filterops snpfiltops_wr =
4c91dbc9 566 { FILTEROP_ISFD, NULL, snpfilter_detach, snpfilter_wr };
5d7a9a94
SG
567
568static int
569snpkqfilter(struct dev_kqfilter_args *ap)
570{
571 cdev_t dev = ap->a_head.a_dev;
572 struct snoop *snp = dev->si_drv1;
573 struct knote *kn = ap->a_kn;
574 struct klist *klist;
575
576 ap->a_result = 0;
577
578 switch (kn->kn_filter) {
579 case EVFILT_READ:
163625b9
SG
580 kn->kn_fop = &snpfiltops_rd;
581 kn->kn_hook = (caddr_t)snp;
582 break;
583 case EVFILT_WRITE:
584 kn->kn_fop = &snpfiltops_wr;
5d7a9a94
SG
585 kn->kn_hook = (caddr_t)snp;
586 break;
587 default:
b287d649 588 ap->a_result = EOPNOTSUPP;
5d7a9a94
SG
589 return (0);
590 }
591
5b22f1a7
SG
592 klist = &snp->snp_kq.ki_note;
593 knote_insert(klist, kn);
5d7a9a94
SG
594
595 return (0);
596}
597
598static void
599snpfilter_detach(struct knote *kn)
600{
601 struct snoop *snp = (struct snoop *)kn->kn_hook;
602 struct klist *klist;
603
5b22f1a7
SG
604 klist = &snp->snp_kq.ki_note;
605 knote_insert(klist, kn);
5d7a9a94
SG
606}
607
608static int
163625b9 609snpfilter_rd(struct knote *kn, long hint)
5d7a9a94
SG
610{
611 struct snoop *snp = (struct snoop *)kn->kn_hook;
612 int ready = 0;
613
614 /*
615 * If snoop is down, we don't want to poll forever so we return 1.
616 * Caller should see if we down via FIONREAD ioctl(). The last should
617 * return -1 to indicate down state.
618 */
619 if (snp->snp_flags & SNOOP_DOWN || snp->snp_len > 0)
620 ready = 1;
621
622 return (ready);
623}
624
163625b9
SG
625static int
626snpfilter_wr(struct knote *kn, long hint)
627{
628 /* Writing is always OK */
629 return (1);
630}
631
8be7edad
MD
632static int
633snpclone(struct dev_clone_args *ap)
634{
635 int unit;
636 unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(snp), 0);
637 ap->a_dev = make_only_dev(&snp_ops, unit, UID_ROOT, GID_WHEEL, 0600,
638 "snp%d", unit);
639
640 return 0;
641}
642
984263bc 643static int
c436375a 644snp_modevent(module_t mod, int type, void *data)
984263bc 645{
8be7edad 646 int i;
984263bc
MD
647
648 switch (type) {
649 case MOD_LOAD:
650 snooplinedisc = ldisc_register(LDISC_LOAD, &snpdisc);
b96f3782
AH
651 make_autoclone_dev(&snp_ops, &DEVFS_CLONE_BITMAP(snp),
652 snpclone, UID_ROOT, GID_WHEEL, 0600, "snp");
8be7edad
MD
653
654 for (i = 0; i < SNP_PREALLOCATED_UNITS; i++) {
655 make_dev(&snp_ops, i, UID_ROOT, GID_WHEEL, 0600, "snp%d", i);
656 devfs_clone_bitmap_set(&DEVFS_CLONE_BITMAP(snp), i);
657 }
984263bc
MD
658 break;
659 case MOD_UNLOAD:
660 if (!LIST_EMPTY(&snp_sclist))
661 return (EBUSY);
662 ldisc_deregister(snooplinedisc);
8be7edad 663 devfs_clone_handler_del("snp");
cd29885a 664 dev_ops_remove_all(&snp_ops);
8be7edad 665 devfs_clone_bitmap_uninit(&DEVFS_CLONE_BITMAP(snp));
984263bc
MD
666 break;
667 default:
668 break;
669 }
670 return (0);
671}
672
673static moduledata_t snp_mod = {
674 "snp",
675 snp_modevent,
676 NULL
677};
678DECLARE_MODULE(snp, snp_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR);