diff options
author | Tobias Weingartner <weingart@cvs.openbsd.org> | 1999-05-09 20:41:49 +0000 |
---|---|---|
committer | Tobias Weingartner <weingart@cvs.openbsd.org> | 1999-05-09 20:41:49 +0000 |
commit | a5524a00ecfb57e5ba4fc29eaded11a8cdfa4e27 (patch) | |
tree | c89aedead0d227b2d124fd794d88691e3d70eac0 | |
parent | 74bbab214892e3b69163545a17bbf9429c32dba9 (diff) |
Fix sdsize() to not call sdopen()/sdclose() unless it is needed.
-rw-r--r-- | sys/scsi/sd.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index c422561ffda..0623e070a6c 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.32 1998/10/04 01:37:55 millert Exp $ */ +/* $OpenBSD: sd.c,v 1.33 1999/05/09 20:41:48 weingart Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /* @@ -1084,18 +1084,29 @@ sdsize(dev) dev_t dev; { struct sd_softc *sd; - int part; + int part, unit, omask; int size; - if (sdopen(dev, 0, S_IFBLK, NULL) != 0) + unit = SDUNIT(dev); + if (unit >= sd_cd.cd_ndevs) return -1; - sd = sd_cd.cd_devs[SDUNIT(dev)]; + sd = sd_cd.cd_devs[unit]; + if (sd == NULL) + return -1; + part = SDPART(dev); - if (sd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) + omask = sd->sc_dk.dk_openmask & (1 << part); + + if (omask == 0 && sdopen(dev, 0, S_IFBLK, NULL) != 0) + return -1; + if ((sd->sc_link->flags & SDEV_MEDIA_LOADED) == 0) + size = -1; + else if (sd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = sd->sc_dk.dk_label->d_partitions[part].p_size; - if (sdclose(dev, 0, S_IFBLK, NULL) != 0) + size = sd->sc_dk.dk_label->d_partitions[part].p_size * + (sd->sc_dk.dk_label->d_secsize / DEV_BSIZE); + if (omask == 0 && sdclose(dev, 0, S_IFBLK, NULL) != 0) return -1; return size; } |