summaryrefslogtreecommitdiff
path: root/sys/dev/isa
diff options
context:
space:
mode:
authorTobias Weingartner <weingart@cvs.openbsd.org>1999-05-09 20:40:44 +0000
committerTobias Weingartner <weingart@cvs.openbsd.org>1999-05-09 20:40:44 +0000
commit74bbab214892e3b69163545a17bbf9429c32dba9 (patch)
tree00ac9791499f32adf6a035a8557b30b147e6e9b9 /sys/dev/isa
parent30f2f00605c73fd483d9bf188a6995032ea790e4 (diff)
Fix wdsize() to not call wdopen/wdclose unless it is needed.
Diffstat (limited to 'sys/dev/isa')
-rw-r--r--sys/dev/isa/wd.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/sys/dev/isa/wd.c b/sys/dev/isa/wd.c
index d6fad600284..56e6ebdbfdc 100644
--- a/sys/dev/isa/wd.c
+++ b/sys/dev/isa/wd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wd.c,v 1.39 1999/02/25 17:14:12 millert Exp $ */
+/* $OpenBSD: wd.c,v 1.40 1999/05/09 20:40:43 weingart Exp $ */
/* $NetBSD: wd.c,v 1.150 1996/05/12 23:54:03 mycroft Exp $ */
/*
@@ -764,20 +764,30 @@ wdsize(dev)
dev_t dev;
{
struct wd_softc *wd;
- int part;
+ int part, unit, omask;
int size;
WDDEBUG_PRINT(("wdsize\n"));
- if (wdopen(dev, 0, S_IFBLK, NULL) != 0)
+ unit = WDUNIT(dev);
+ if (unit >= wd_cd.cd_ndevs)
+ return -1;
+ wd = wd_cd.cd_devs[unit];
+ if (wd == NULL)
return -1;
- wd = wd_cd.cd_devs[WDUNIT(dev)];
+
part = WDPART(dev);
- if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
+ omask = wd->sc_dk.dk_openmask & (1 << part);
+
+ if (omask == 0 && wdopen(dev, 0, S_IFBLK, NULL) != 0)
+ return -1;
+ else if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
else
- size = wd->sc_dk.dk_label->d_partitions[part].p_size;
- if (wdclose(dev, 0, S_IFBLK, NULL) != 0)
+ size = wd->sc_dk.dk_label->d_partitions[part].p_size *
+ (wd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
+
+ if (omask == 0 && wdclose(dev, 0, S_IFBLK, NULL) != 0)
return -1;
return size;
}