FreeBSD Bugzilla – Attachment 8408 Details for
Bug 17629
"almost clone" patch for device snp
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 4.76 KB, created by
brooks
on 2000-03-28 03:20:01 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
brooks
Created:
2000-03-28 03:20:01 UTC
Size:
4.76 KB
patch
obsolete
>Index: tty_snoop.c >=================================================================== >RCS file: /home/ncvs/src/sys/kern/tty_snoop.c,v >retrieving revision 1.45 >diff -u -r1.45 tty_snoop.c >--- tty_snoop.c 1999/11/18 06:39:47 1.45 >+++ tty_snoop.c 2000/03/28 01:30:32 >@@ -32,6 +32,8 @@ > #include <sys/snoop.h> > #include <sys/vnode.h> > >+MALLOC_DEFINE(M_SNP, "snp", "Snoop Interface"); >+ > static d_open_t snpopen; > static d_close_t snpclose; > static d_read_t snpread; >@@ -62,8 +64,6 @@ > #define MIN(a,b) (((a)<(b))?(a):(b)) > #endif > >-static struct snoop snoopsw[NSNP]; >- > static struct tty *snpdevtotty __P((dev_t dev)); > static int snp_detach __P((struct snoop *snp)); > >@@ -90,8 +90,8 @@ > struct uio *uio; > int flag; > { >- int unit = minor(dev), len, i, error; >- struct snoop *snp = &snoopsw[unit]; >+ int len, i, error; >+ struct snoop *snp = dev->si_drv1; > struct tty *tp; > char c[SNP_INPUT_BUF]; > >@@ -131,8 +131,8 @@ > struct uio *uio; > int flag; > { >- int unit = minor(dev), s; >- struct snoop *snp = &snoopsw[unit]; >+ int s; >+ struct snoop *snp = dev->si_drv1; > int len, n, nblen, error = 0; > caddr_t from; > char *nbuf; >@@ -174,9 +174,9 @@ > if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) { > while (((nblen / 2) >= snp->snp_len) && ((nblen / 2) >= SNOOP_MINLEN)) > nblen = nblen / 2; >- if ((nbuf = malloc(nblen, M_TTYS, M_NOWAIT)) != NULL) { >+ if ((nbuf = malloc(nblen, M_SNP, M_NOWAIT)) != NULL) { > bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); >- free(snp->snp_buf, M_TTYS); >+ free(snp->snp_buf, M_SNP); > snp->snp_buf = nbuf; > snp->snp_blen = nblen; > snp->snp_base = 0; >@@ -213,12 +213,6 @@ > if (n == 0) > return 0; > >-#ifdef DIAGNOSTIC >- if (!(snp->snp_flags & SNOOP_OPEN)) { >- printf("Snoop: data coming to closed device.\n"); >- return 0; >- } >-#endif > if (snp->snp_flags & SNOOP_DOWN) { > printf("Snoop: more data to down interface.\n"); > return 0; >@@ -246,9 +240,9 @@ > nblen = snp->snp_blen * 2; > s_free = nblen - (snp->snp_len + snp->snp_base); > } >- if ((n <= s_free) && (nbuf = malloc(nblen, M_TTYS, M_NOWAIT))) { >+ if ((n <= s_free) && (nbuf = malloc(nblen, M_SNP, M_NOWAIT))) { > bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); >- free(snp->snp_buf, M_TTYS); >+ free(snp->snp_buf, M_SNP); > snp->snp_buf = nbuf; > snp->snp_blen = nblen; > snp->snp_base = 0; >@@ -291,26 +285,22 @@ > struct proc *p; > { > struct snoop *snp; >- register int unit, error; >+ register int error; > > if ((error = suser(p)) != 0) > return (error); > >- if ((unit = minor(dev)) >= NSNP) >- return (ENXIO); >+ snp = dev->si_drv1; > >- snp = &snoopsw[unit]; >+ if (snp) >+ return (EBUSY); > >- if (snp->snp_flags & SNOOP_OPEN) >- return (ENXIO); >+ make_dev(&snp_cdevsw, minor(dev), 0, 0, 0600, "bpf%d", lminor(dev)); >+ MALLOC(snp, struct snoop *, sizeof(*snp), M_SNP, M_WAITOK); >+ bzero(snp, sizeof(*snp)); >+ dev->si_drv1 = snp; > >- /* >- * We intentionally do not OR flags with SNOOP_OPEN,but set them so >- * all previous settings (especially SNOOP_OFLOW) will be cleared. >- */ >- snp->snp_flags = SNOOP_OPEN; >- >- snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); >+ snp->snp_buf = malloc(SNOOP_MINLEN, M_SNP, M_WAITOK); > snp->snp_blen = SNOOP_MINLEN; > snp->snp_base = 0; > snp->snp_len = 0; >@@ -367,14 +357,15 @@ > int fmt; > struct proc *p; > { >- register int unit = minor(dev); >- struct snoop *snp = &snoopsw[unit]; >+ int error; >+ struct snoop *snp = dev->si_drv1; > >- snp->snp_blen = 0; >- free(snp->snp_buf, M_TTYS); >- snp->snp_flags &= ~SNOOP_OPEN; >+ free(snp->snp_buf, M_SNP); >+ error = snp_detach(snp); >+ FREE(snp, M_SNP); >+ dev->si_drv1 = 0; > >- return (snp_detach(snp)); >+ return (error); > } > > int >@@ -382,8 +373,8 @@ > struct snoop *snp; > { > snp->snp_blen = SNOOP_MINLEN; >- free(snp->snp_buf, M_TTYS); >- snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); >+ free(snp->snp_buf, M_SNP); >+ snp->snp_buf = malloc(SNOOP_MINLEN, M_SNP, M_WAITOK); > snp->snp_flags |= SNOOP_DOWN; > > return (snp_detach(snp)); >@@ -398,9 +389,9 @@ > int flags; > struct proc *p; > { >- int unit = minor(dev), s; >+ int s; > dev_t tdev; >- struct snoop *snp = &snoopsw[unit]; >+ struct snoop *snp = dev->si_drv1; > struct tty *tp, *tpo; > > switch (cmd) { >@@ -489,8 +480,7 @@ > int events; > struct proc *p; > { >- int unit = minor(dev); >- struct snoop *snp = &snoopsw[unit]; >+ struct snoop *snp = dev->si_drv1; > int revents = 0; > > >@@ -514,10 +504,8 @@ > snp_drvinit(unused) > void *unused; > { >- int i; > >- for (i = 0; i < NSNP; i++) >- make_dev(&snp_cdevsw, i, 0, 0, 0600, "snp%d", i); >+ cdevsw_add(&snp_cdevsw); > } > > SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 17629
: 8408