diff options
author | Tobias Weingartner <weingart@cvs.openbsd.org> | 1999-05-09 20:40:44 +0000 |
---|---|---|
committer | Tobias Weingartner <weingart@cvs.openbsd.org> | 1999-05-09 20:40:44 +0000 |
commit | 74bbab214892e3b69163545a17bbf9429c32dba9 (patch) | |
tree | 00ac9791499f32adf6a035a8557b30b147e6e9b9 | |
parent | 30f2f00605c73fd483d9bf188a6995032ea790e4 (diff) |
Fix wdsize() to not call wdopen/wdclose unless it is needed.
-rw-r--r-- | sys/dev/isa/wd.c | 24 |
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; } |