diff options
-rw-r--r-- | sys/dev/ata/atapi-cd.c | 10 | ||||
-rw-r--r-- | sys/dev/ata/atapi-cd.h | 1 | ||||
-rw-r--r-- | sys/dev/ata/atapi-fd.c | 10 | ||||
-rw-r--r-- | sys/dev/ata/atapi-fd.h | 1 | ||||
-rw-r--r-- | sys/dev/ata/atapi-tape.c | 7 | ||||
-rw-r--r-- | sys/dev/ata/atapi-tape.h | 9 | ||||
-rw-r--r-- | sys/kern/vfs_export.c | 16 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 16 | ||||
-rw-r--r-- | sys/sys/conf.h | 1 | ||||
-rw-r--r-- | sys/sys/linedisc.h | 1 |
10 files changed, 51 insertions, 21 deletions
diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c index 9b6c453..dbacde7 100644 --- a/sys/dev/ata/atapi-cd.c +++ b/sys/dev/ata/atapi-cd.c @@ -451,13 +451,13 @@ acdopen(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) return EBUSY; if (flags & FWRITE) { - if (cdp->refcnt) + if (count_dev(dev) > 1) return EBUSY; else cdp->flags |= F_WRITING; } - if (!cdp->refcnt++) { + if (count_dev(dev) == 1) { acd_prevent_allow(cdp, 1); cdp->flags |= F_LOCKED; if (!(flags & O_NONBLOCK) && !(flags & FWRITE)) @@ -473,7 +473,7 @@ acdclose(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) { struct acd_softc *cdp = dev->si_drv1; - if (!--cdp->refcnt) + if (count_dev(dev) == 1) acd_prevent_allow(cdp, 0); cdp->flags &= ~(F_LOCKED | F_WRITING); @@ -536,7 +536,7 @@ acdioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p) break; case CDIOCEJECT: - if (cdp->refcnt > 1) { + if (count_dev(dev) > 1) { error = EBUSY; break; } @@ -544,7 +544,7 @@ acdioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p) break; case CDIOCCLOSE: - if (cdp->refcnt > 1) + if (count_dev(dev) > 1) break; error = acd_eject(cdp, 1); break; diff --git a/sys/dev/ata/atapi-cd.h b/sys/dev/ata/atapi-cd.h index 90e284f..6345ded 100644 --- a/sys/dev/ata/atapi-cd.h +++ b/sys/dev/ata/atapi-cd.h @@ -317,7 +317,6 @@ struct acd_softc { #define F_DISK_OPEN 0x0008 /* disk open for writing */ #define F_TRACK_OPEN 0x0010 /* track open for writing */ - int32_t refcnt; /* the number of raw opens */ struct buf_queue_head buf_queue; /* Queue of i/o requests */ struct toc toc; /* table of disc contents */ struct { diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index 51a4e06..1ad955e 100644 --- a/sys/dev/ata/atapi-fd.c +++ b/sys/dev/ata/atapi-fd.c @@ -215,7 +215,7 @@ afdopen(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) atapi_test_ready(fdp->atp); - if (!fdp->refcnt++) + if (count_dev(dev) == 1) afd_prevent_allow(fdp, 1); if (afd_sense(fdp)) @@ -238,7 +238,7 @@ afdclose(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) { struct afd_softc *fdp = dev->si_drv1; - if (!--fdp->refcnt) + if (count_dev(dev) == 1) afd_prevent_allow(fdp, 0); return 0; } @@ -250,12 +250,12 @@ afdioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p) switch (cmd) { case CDIOCEJECT: - if (fdp->refcnt > 1) + if (count_dev(dev) > 1) return EBUSY; return afd_eject(fdp, 0); case CDIOCCLOSE: - if (fdp->refcnt > 1) + if (count_dev(dev) > 1) return 0; return afd_eject(fdp, 1); @@ -305,7 +305,7 @@ afd_start(struct afd_softc *fdp) } lba = bp->b_pblkno / (fdp->cap.sector_size / DEV_BSIZE); - count = (bp->b_bcount + (fdp->cap.sector_size - 1)) / fdp->cap.sector_size; + count = bp->b_bcount; data_ptr = bp->b_data; bp->b_resid = 0; diff --git a/sys/dev/ata/atapi-fd.h b/sys/dev/ata/atapi-fd.h index fcef411..f2c77f0 100644 --- a/sys/dev/ata/atapi-fd.h +++ b/sys/dev/ata/atapi-fd.h @@ -73,7 +73,6 @@ struct afd_cappage { struct afd_softc { struct atapi_softc *atp; /* controller structure */ int32_t lun; /* logical device unit */ - int32_t refcnt; /* the number of raw opens */ int32_t transfersize; /* max size of each transfer */ struct buf_queue_head buf_queue; /* queue of i/o requests */ struct afd_header header; /* capabilities page info */ diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c index 93e42e9..81953c2 100644 --- a/sys/dev/ata/atapi-tape.c +++ b/sys/dev/ata/atapi-tape.c @@ -240,7 +240,7 @@ astopen(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) if (!stp) return ENXIO; - if (stp->flags == F_OPEN) + if (count_dev(dev) > 1) return EBUSY; atapi_test_ready(stp->atp); @@ -253,7 +253,6 @@ astopen(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) stp->atp->flags &= ~ATAPI_F_MEDIA_CHANGED; stp->flags &= ~(F_DATA_WRITTEN | F_FM_WRITTEN); - stp->flags |= F_OPEN; ast_total = 0; return 0; } @@ -276,10 +275,10 @@ astclose(dev_t dev, int32_t flags, int32_t fmt, struct proc *p) if (!(minor(dev) & 0x01)) ast_rewind(stp); - if (stp->cap.lock) + if (stp->cap.lock && count_dev(dev) == 1) ast_prevent_allow(stp, 0); - stp->flags &= ~(F_OPEN | F_CTL_WARN); + stp->flags &= F_CTL_WARN; #ifdef AST_DEBUG printf("ast%d: %llu total bytes transferred\n", stp->lun, ast_total); #endif diff --git a/sys/dev/ata/atapi-tape.h b/sys/dev/ata/atapi-tape.h index b2c00fb..98719bf 100644 --- a/sys/dev/ata/atapi-tape.h +++ b/sys/dev/ata/atapi-tape.h @@ -147,11 +147,10 @@ struct ast_softc { struct atapi_softc *atp; /* controller structure */ int32_t lun; /* logical device unit */ int32_t flags; /* device state flags */ -#define F_OPEN 0x0001 /* the device is opened */ -#define F_CTL_WARN 0x0002 /* warned about CTL wrong? */ -#define F_WRITEPROTECT 0x0004 /* media is writeprotected */ -#define F_DATA_WRITTEN 0x0010 /* data has been written */ -#define F_FM_WRITTEN 0x0020 /* filemark has been written */ +#define F_CTL_WARN 0x0001 /* warned about CTL wrong? */ +#define F_WRITEPROTECT 0x0002 /* media is writeprotected */ +#define F_DATA_WRITTEN 0x0004 /* data has been written */ +#define F_FM_WRITTEN 0x0008 /* filemark has been written */ #define F_ONSTREAM 0x0100 /* OnStream ADR device */ int32_t blksize; /* block size (512 | 1024) */ diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 06cc0d8..9120f77 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -1933,6 +1933,22 @@ vcount(vp) } /* + * Same as above, but using the dev_t as argument + */ + +int +count_dev(dev) + dev_t dev; +{ + struct vnode *vp; + + vp = SLIST_FIRST(&dev->si_hlist); + if (vp == NULL) + return (0); + return(vcount(vp)); +} + +/* * Print out a description of a vnode. */ static char *typename[] = diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 06cc0d8..9120f77 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1933,6 +1933,22 @@ vcount(vp) } /* + * Same as above, but using the dev_t as argument + */ + +int +count_dev(dev) + dev_t dev; +{ + struct vnode *vp; + + vp = SLIST_FIRST(&dev->si_hlist); + if (vp == NULL) + return (0); + return(vcount(vp)); +} + +/* * Print out a description of a vnode. */ static char *typename[] = diff --git a/sys/sys/conf.h b/sys/sys/conf.h index f4f6112..263613c 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -258,6 +258,7 @@ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) int cdevsw_add __P((struct cdevsw *new)); int cdevsw_remove __P((struct cdevsw *old)); +int count_dev __P((dev_t dev)); void destroy_dev __P((dev_t dev)); struct cdevsw *devsw __P((dev_t dev)); const char *devtoname __P((dev_t dev)); diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h index f4f6112..263613c 100644 --- a/sys/sys/linedisc.h +++ b/sys/sys/linedisc.h @@ -258,6 +258,7 @@ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) int cdevsw_add __P((struct cdevsw *new)); int cdevsw_remove __P((struct cdevsw *old)); +int count_dev __P((dev_t dev)); void destroy_dev __P((dev_t dev)); struct cdevsw *devsw __P((dev_t dev)); const char *devtoname __P((dev_t dev)); |