Deleted Added
full compact
snp.c (12577) snp.c (12675)
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

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

25#define TTYDEFCHARS
26#include <sys/tty.h>
27#undef TTYDEFCHARS
28#include <sys/file.h>
29#include <sys/conf.h>
30#include <sys/uio.h>
31#include <sys/kernel.h>
32#include <sys/malloc.h>
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

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

25#define TTYDEFCHARS
26#include <sys/tty.h>
27#undef TTYDEFCHARS
28#include <sys/file.h>
29#include <sys/conf.h>
30#include <sys/uio.h>
31#include <sys/kernel.h>
32#include <sys/malloc.h>
33
34#include <sys/snoop.h>
35
36#ifdef JREMOD
37#ifdef DEVFS
38#include <sys/devfsext.h>
39#endif /*DEVFS*/
33#ifdef DEVFS
34#include <sys/devfsext.h>
35#endif /*DEVFS*/
36
37#include <sys/snoop.h>
38
39static d_open_t snpopen;
40static d_close_t snpclose;
41static d_read_t snpread;
42static d_write_t snpwrite;
43static d_ioctl_t snpioctl;
44static d_select_t snpselect;
45
40#define CDEV_MAJOR 53
46#define CDEV_MAJOR 53
41#endif /*JREMOD*/
47struct cdevsw snp_cdevsw =
48 { snpopen, snpclose, snpread, snpwrite, /*53*/
49 snpioctl, nostop, nullreset, nodevtotty,/* snoop */
50 snpselect, nommap, NULL, "snp", NULL, -1 };
42
51
52
43#ifndef MIN
44#define MIN(a,b) (((a)<(b))?(a):(b))
45#endif
46
47static struct snoop snoopsw[NSNP];
48
49static struct tty *devtotty __P((dev_t dev));
50

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

58 return (*cdevsw[major(dev)].d_devtotty)(dev);
59}
60
61#define SNP_INPUT_BUF 5 /* This is even too much,the maximal
62 * interactive mode write is 3 bytes
63 * length for function keys...
64 */
65
53#ifndef MIN
54#define MIN(a,b) (((a)<(b))?(a):(b))
55#endif
56
57static struct snoop snoopsw[NSNP];
58
59static struct tty *devtotty __P((dev_t dev));
60

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

68 return (*cdevsw[major(dev)].d_devtotty)(dev);
69}
70
71#define SNP_INPUT_BUF 5 /* This is even too much,the maximal
72 * interactive mode write is 3 bytes
73 * length for function keys...
74 */
75
66int
76static int
67snpwrite(dev, uio, flag)
68 dev_t dev;
69 struct uio *uio;
70 int flag;
71{
72 int unit = minor(dev), len, i, error;
73 struct snoop *snp = &snoopsw[unit];
74 struct tty *tp;

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

99 return (EIO);
100 }
101 }
102 return 0;
103
104}
105
106
77snpwrite(dev, uio, flag)
78 dev_t dev;
79 struct uio *uio;
80 int flag;
81{
82 int unit = minor(dev), len, i, error;
83 struct snoop *snp = &snoopsw[unit];
84 struct tty *tp;

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

109 return (EIO);
110 }
111 }
112 return 0;
113
114}
115
116
107int
117static int
108snpread(dev, uio, flag)
109 dev_t dev;
110 struct uio *uio;
111 int flag;
112{
113 int unit = minor(dev), s;
114 struct snoop *snp = &snoopsw[unit];
115 int len, n, nblen, error = 0;

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

265 wakeup((caddr_t) snp);
266 }
267 selwakeup(&snp->snp_sel);
268 snp->snp_sel.si_pid = 0;
269
270 return n;
271}
272
118snpread(dev, uio, flag)
119 dev_t dev;
120 struct uio *uio;
121 int flag;
122{
123 int unit = minor(dev), s;
124 struct snoop *snp = &snoopsw[unit];
125 int len, n, nblen, error = 0;

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

275 wakeup((caddr_t) snp);
276 }
277 selwakeup(&snp->snp_sel);
278 snp->snp_sel.si_pid = 0;
279
280 return n;
281}
282
273int
283static int
274snpopen(dev, flag, mode, p)
275 dev_t dev;
276 int flag, mode;
277 struct proc *p;
278{
279 struct snoop *snp;
280 register int unit, error;
281

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

341
342detach_notty:
343 selwakeup(&snp->snp_sel);
344 snp->snp_sel.si_pid = 0;
345
346 return (0);
347}
348
284snpopen(dev, flag, mode, p)
285 dev_t dev;
286 int flag, mode;
287 struct proc *p;
288{
289 struct snoop *snp;
290 register int unit, error;
291

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

351
352detach_notty:
353 selwakeup(&snp->snp_sel);
354 snp->snp_sel.si_pid = 0;
355
356 return (0);
357}
358
349int
359static int
350snpclose(dev, flags, fmt, p)
351 dev_t dev;
352 int flags;
353 int fmt;
354 struct proc *p;
355{
356 register int unit = minor(dev);
357 struct snoop *snp = &snoopsw[unit];

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

371 free(snp->snp_buf, M_TTYS);
372 snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
373 snp->snp_flags |= SNOOP_DOWN;
374
375 return (snp_detach(snp));
376}
377
378
360snpclose(dev, flags, fmt, p)
361 dev_t dev;
362 int flags;
363 int fmt;
364 struct proc *p;
365{
366 register int unit = minor(dev);
367 struct snoop *snp = &snoopsw[unit];

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

381 free(snp->snp_buf, M_TTYS);
382 snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
383 snp->snp_flags |= SNOOP_DOWN;
384
385 return (snp_detach(snp));
386}
387
388
379int
389static int
380snpioctl(dev, cmd, data, flags, p)
381 dev_t dev;
382 int cmd;
383 caddr_t data;
384 int flags;
385 struct proc *p;
386{
387 int unit = minor(dev), s;

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

468
469 default:
470 return (ENOTTY);
471 }
472 return (0);
473}
474
475
390snpioctl(dev, cmd, data, flags, p)
391 dev_t dev;
392 int cmd;
393 caddr_t data;
394 int flags;
395 struct proc *p;
396{
397 int unit = minor(dev), s;

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

478
479 default:
480 return (ENOTTY);
481 }
482 return (0);
483}
484
485
476int
486static int
477snpselect(dev, rw, p)
478 dev_t dev;
479 int rw;
480 struct proc *p;
481{
482 int unit = minor(dev);
483 struct snoop *snp = &snoopsw[unit];
484

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

495 */
496 if (snp->snp_flags & SNOOP_DOWN)
497 return 1;
498
499 selrecord(p, &snp->snp_sel);
500 return 0;
501}
502
487snpselect(dev, rw, p)
488 dev_t dev;
489 int rw;
490 struct proc *p;
491{
492 int unit = minor(dev);
493 struct snoop *snp = &snoopsw[unit];
494

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

505 */
506 if (snp->snp_flags & SNOOP_DOWN)
507 return 1;
508
509 selrecord(p, &snp->snp_sel);
510 return 0;
511}
512
503#ifdef JREMOD
504struct cdevsw snp_cdevsw =
505 { snpopen, snpclose, snpread, snpwrite, /*53*/
506 snpioctl, nostop, nullreset, nodevtotty,/* snoop */
507 snpselect, nommap, NULL };
508
513static void *snp_devfs_token[NSNP];
509static snp_devsw_installed = 0;
510
514static snp_devsw_installed = 0;
515
511static void snp_drvinit(void *unused)
516static void
517snp_drvinit(void *unused)
512{
513 dev_t dev;
518{
519 dev_t dev;
520 char name[32];
521 int i;
514
515 if( ! snp_devsw_installed ) {
522
523 if( ! snp_devsw_installed ) {
516 dev = makedev(CDEV_MAJOR,0);
517 cdevsw_add(&dev,&snp_cdevsw,NULL);
524 dev = makedev(CDEV_MAJOR, 0);
525 cdevsw_add(&dev,&snp_cdevsw, NULL);
518 snp_devsw_installed = 1;
519#ifdef DEVFS
526 snp_devsw_installed = 1;
527#ifdef DEVFS
520 {
521 int x;
522/* default for a simple device with no probe routine (usually delete this) */
523 x=devfs_add_devsw(
524/* path name devsw minor type uid gid perm*/
525 "/", "snp", major(dev), 0, DV_CHR, 0, 0, 0600);
528 for ( i = 0 ; i < NSNP ; i++) {
529 sprintf(name,"snp%d",i);
530 snp_devfs_token[i] =
531 devfs_add_devsw( "/", name, &snp_cdevsw, i,
532 DV_CHR, 0, 0, 0600);
526 }
527#endif
528 }
529}
530
531SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL)
532
533 }
534#endif
535 }
536}
537
538SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL)
539
533#endif /* JREMOD */
534
535#endif
540
541#endif