summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorsos <sos@FreeBSD.org>2000-02-07 23:05:40 +0000
committersos <sos@FreeBSD.org>2000-02-07 23:05:40 +0000
commitdc230127daec112c1a3bb700232c22ac04631e88 (patch)
treee072c7f077d8cba1f690c8122a148d5cad899a12 /sys/dev
parenta3a1cb67da99bf7ec2e1c0d9321f78e13d17bbc5 (diff)
downloadFreeBSD-src-dc230127daec112c1a3bb700232c22ac04631e88.zip
FreeBSD-src-dc230127daec112c1a3bb700232c22ac04631e88.tar.gz
Do refcounting of open devices (more) correctly.
count_dev funtion by phk.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ata/atapi-cd.c10
-rw-r--r--sys/dev/ata/atapi-cd.h1
-rw-r--r--sys/dev/ata/atapi-fd.c10
-rw-r--r--sys/dev/ata/atapi-fd.h1
-rw-r--r--sys/dev/ata/atapi-tape.c7
-rw-r--r--sys/dev/ata/atapi-tape.h9
6 files changed, 17 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) */
OpenPOWER on IntegriCloud