summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/boot/sys/boot/common/disk.c180
-rw-r--r--usr/src/boot/sys/boot/common/disk.h29
-rw-r--r--usr/src/boot/sys/boot/i386/libi386/biosdisk.c23
-rw-r--r--usr/src/boot/sys/boot/uboot/lib/disk.c3
-rw-r--r--usr/src/boot/sys/boot/usb/storage/umass_loader.c2
-rw-r--r--usr/src/boot/sys/boot/userboot/userboot/userboot_disk.c4
6 files changed, 36 insertions, 205 deletions
diff --git a/usr/src/boot/sys/boot/common/disk.c b/usr/src/boot/sys/boot/common/disk.c
index 088013b0c6..0c9bf0e0db 100644
--- a/usr/src/boot/sys/boot/common/disk.c
+++ b/usr/src/boot/sys/boot/common/disk.c
@@ -26,8 +26,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/disk.h>
#include <sys/queue.h>
#include <stand.h>
@@ -48,8 +46,6 @@ struct open_disk {
uint64_t mediasize;
uint64_t entrysize;
u_int sectorsize;
- u_int flags;
- int rcnt;
};
struct print_args {
@@ -58,96 +54,6 @@ struct print_args {
int verbose;
};
-struct dentry {
- const struct devsw *d_dev;
- int d_unit;
- int d_slice;
- int d_partition;
-
- struct open_disk *od;
- uint64_t d_offset;
- STAILQ_ENTRY(dentry) entry;
-#ifdef DISK_DEBUG
- uint32_t count;
-#endif
-};
-
-static STAILQ_HEAD(, dentry) opened_disks =
- STAILQ_HEAD_INITIALIZER(opened_disks);
-
-static int
-disk_lookup(struct disk_devdesc *dev)
-{
- struct dentry *entry;
- int rc;
-
- rc = ENOENT;
- STAILQ_FOREACH(entry, &opened_disks, entry) {
- if (entry->d_dev != dev->d_dev ||
- entry->d_unit != dev->d_unit)
- continue;
- dev->d_opendata = entry->od;
- if (entry->d_slice == dev->d_slice &&
- entry->d_partition == dev->d_partition) {
- dev->d_offset = entry->d_offset;
- DEBUG("%s offset %lld", disk_fmtdev(dev),
- (long long)dev->d_offset);
-#ifdef DISK_DEBUG
- entry->count++;
-#endif
- return (0);
- }
- rc = EAGAIN;
- }
- return (rc);
-}
-
-static void
-disk_insert(struct disk_devdesc *dev)
-{
- struct dentry *entry;
-
- entry = (struct dentry *)malloc(sizeof(struct dentry));
- if (entry == NULL) {
- DEBUG("no memory");
- return;
- }
- entry->d_dev = dev->d_dev;
- entry->d_unit = dev->d_unit;
- entry->d_slice = dev->d_slice;
- entry->d_partition = dev->d_partition;
- entry->od = (struct open_disk *)dev->d_opendata;
- entry->od->rcnt++;
- entry->d_offset = dev->d_offset;
-#ifdef DISK_DEBUG
- entry->count = 1;
-#endif
- STAILQ_INSERT_TAIL(&opened_disks, entry, entry);
- DEBUG("%s cached", disk_fmtdev(dev));
-}
-
-#ifdef DISK_DEBUG
-COMMAND_SET(dcachestat, "dcachestat", "get disk cache stats",
- command_dcachestat);
-
-static int
-command_dcachestat(int argc, char *argv[])
-{
- struct disk_devdesc dev;
- struct dentry *entry;
-
- STAILQ_FOREACH(entry, &opened_disks, entry) {
- dev.d_dev = (struct devsw *)entry->d_dev;
- dev.d_unit = entry->d_unit;
- dev.d_slice = entry->d_slice;
- dev.d_partition = entry->d_partition;
- printf("%s %d => %p [%d]\n", disk_fmtdev(&dev), entry->count,
- entry->od, entry->od->rcnt);
- }
- return (CMD_OK);
-}
-#endif /* DISK_DEBUG */
-
/* Convert size to a human-readable number. */
static char *
display_size(uint64_t size, u_int sectorsize)
@@ -289,8 +195,7 @@ disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *data)
}
int
-disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize,
- u_int flags)
+disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize)
{
struct open_disk *od;
struct ptable *table;
@@ -298,11 +203,6 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize,
int rc, slice, partition;
rc = 0;
- if ((flags & DISK_F_NOCACHE) == 0) {
- rc = disk_lookup(dev);
- if (rc == 0)
- return (0);
- }
/*
* While we are reading disk metadata, make sure we do it relative
* to the start of the disk
@@ -311,30 +211,15 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize,
table = NULL;
slice = dev->d_slice;
partition = dev->d_partition;
- if (rc == EAGAIN) {
- /*
- * This entire disk was already opened and there is no
- * need to allocate new open_disk structure and open the
- * main partition table.
- */
- od = (struct open_disk *)dev->d_opendata;
- DEBUG("%s unit %d, slice %d, partition %d => %p (cached)",
- disk_fmtdev(dev), dev->d_unit, dev->d_slice,
- dev->d_partition, od);
- goto opened;
- } else {
- od = (struct open_disk *)malloc(sizeof(struct open_disk));
- if (od == NULL) {
- DEBUG("no memory");
- return (ENOMEM);
- }
- dev->d_opendata = od;
- od->rcnt = 0;
- od->entrysize = 0;
+ od = (struct open_disk *)malloc(sizeof(struct open_disk));
+ if (od == NULL) {
+ DEBUG("no memory");
+ return (ENOMEM);
}
+ dev->d_opendata = od;
+ od->entrysize = 0;
od->mediasize = mediasize;
od->sectorsize = sectorsize;
- od->flags = flags;
DEBUG("%s unit %d, slice %d, partition %d => %p",
disk_fmtdev(dev), dev->d_unit, dev->d_slice, dev->d_partition, od);
@@ -354,8 +239,7 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize, u_int sectorsize,
if (mediasize > od->mediasize) {
od->mediasize = mediasize;
}
-opened:
- rc = 0;
+
if (ptable_gettype(od->table) == PTABLE_BSD &&
partition >= 0) {
/* It doesn't matter what value has d_slice */
@@ -424,15 +308,11 @@ out:
ptable_close(table);
if (rc != 0) {
- if (od->rcnt < 1) {
- if (od->table != NULL)
- ptable_close(od->table);
- free(od);
- }
+ if (od->table != NULL)
+ ptable_close(od->table);
+ free(od);
DEBUG("%s could not open", disk_fmtdev(dev));
} else {
- if ((flags & DISK_F_NOCACHE) == 0)
- disk_insert(dev);
/* Save the slice and partition number to the dev */
dev->d_slice = slice;
dev->d_partition = partition;
@@ -448,44 +328,12 @@ disk_close(struct disk_devdesc *dev)
struct open_disk *od;
od = (struct open_disk *)dev->d_opendata;
- DEBUG("%s closed => %p [%d]", disk_fmtdev(dev), od, od->rcnt);
- if (od->flags & DISK_F_NOCACHE) {
- ptable_close(od->table);
- free(od);
- }
+ DEBUG("%s closed => %p", disk_fmtdev(dev), od);
+ ptable_close(od->table);
+ free(od);
return (0);
}
-void
-disk_cleanup(const struct devsw *d_dev)
-{
-#ifdef DISK_DEBUG
- struct disk_devdesc dev;
-#endif
- struct dentry *entry, *tmp;
-
- STAILQ_FOREACH_SAFE(entry, &opened_disks, entry, tmp) {
- if (entry->d_dev != d_dev)
- continue;
- entry->od->rcnt--;
-#ifdef DISK_DEBUG
- dev.d_dev = (struct devsw *)entry->d_dev;
- dev.d_unit = entry->d_unit;
- dev.d_slice = entry->d_slice;
- dev.d_partition = entry->d_partition;
- DEBUG("%s was freed => %p [%d]", disk_fmtdev(&dev),
- entry->od, entry->od->rcnt);
-#endif
- STAILQ_REMOVE(&opened_disks, entry, dentry, entry);
- if (entry->od->rcnt < 1) {
- if (entry->od->table != NULL)
- ptable_close(entry->od->table);
- free(entry->od);
- }
- free(entry);
- }
-}
-
char*
disk_fmtdev(struct disk_devdesc *dev)
{
diff --git a/usr/src/boot/sys/boot/common/disk.h b/usr/src/boot/sys/boot/common/disk.h
index 6b52c09748..4f1666b1b7 100644
--- a/usr/src/boot/sys/boot/common/disk.h
+++ b/usr/src/boot/sys/boot/common/disk.h
@@ -22,8 +22,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
/*
@@ -83,6 +81,9 @@
* the device's strategy method.
*/
+#ifndef _DISK_H
+#define _DISK_H
+
struct disk_devdesc
{
struct devsw *d_dev;
@@ -102,21 +103,17 @@ enum disk_ioctl {
/*
* Parse disk metadata and initialise dev->d_offset.
*/
-extern int disk_open(struct disk_devdesc *dev, uint64_t mediasize,
- u_int sectorsize, u_int flags);
-#define DISK_F_NOCACHE 0x0001 /* Do not use metadata caching */
-extern int disk_close(struct disk_devdesc *dev);
-extern void disk_cleanup(const struct devsw *d_dev);
-extern int disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf);
-extern int disk_read(struct disk_devdesc *dev, void *buf, uint64_t offset,
- u_int blocks);
-extern int disk_write(struct disk_devdesc *dev, void *buf, uint64_t offset,
- u_int blocks);
+extern int disk_open(struct disk_devdesc *, uint64_t, u_int);
+extern int disk_close(struct disk_devdesc *);
+extern int disk_ioctl(struct disk_devdesc *, u_long, void *);
+extern int disk_read(struct disk_devdesc *, void *, uint64_t, u_int);
+extern int disk_write(struct disk_devdesc *, void *, uint64_t, u_int);
/*
* Print information about slices on a disk.
*/
-extern int disk_print(struct disk_devdesc *dev, char *prefix, int verbose);
-extern char* disk_fmtdev(struct disk_devdesc *dev);
-extern int disk_parsedev(struct disk_devdesc *dev, const char *devspec,
- const char **path);
+extern int disk_print(struct disk_devdesc *, char *, int);
+extern char* disk_fmtdev(struct disk_devdesc *);
+extern int disk_parsedev(struct disk_devdesc *, const char *, const char **);
+
+#endif /* _DISK_H */
diff --git a/usr/src/boot/sys/boot/i386/libi386/biosdisk.c b/usr/src/boot/sys/boot/i386/libi386/biosdisk.c
index cd6891b721..4c44f5b3d4 100644
--- a/usr/src/boot/sys/boot/i386/libi386/biosdisk.c
+++ b/usr/src/boot/sys/boot/i386/libi386/biosdisk.c
@@ -108,7 +108,6 @@ static int bd_open(struct open_file *f, ...);
static int bd_close(struct open_file *f);
static int bd_ioctl(struct open_file *f, u_long cmd, void *data);
static int bd_print(int verbose);
-static void bd_cleanup(void);
struct devsw biosdisk = {
"disk",
@@ -119,7 +118,7 @@ struct devsw biosdisk = {
bd_close,
bd_ioctl,
bd_print,
- bd_cleanup
+ NULL
};
/*
@@ -189,13 +188,6 @@ bd_init(void)
return(0);
}
-static void
-bd_cleanup(void)
-{
-
- disk_cleanup(&biosdisk);
-}
-
/*
* Try to detect a device supported by the legacy int13 BIOS
*/
@@ -324,9 +316,7 @@ bd_print(int verbose)
dev.d_partition = -1;
if (disk_open(&dev,
bdinfo[i].bd_sectorsize * bdinfo[i].bd_sectors,
- bdinfo[i].bd_sectorsize,
- (bdinfo[i].bd_flags & BD_FLOPPY) ?
- DISK_F_NOCACHE: 0) == 0) {
+ bdinfo[i].bd_sectorsize) == 0) {
sprintf(line, " disk%d", i);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
@@ -381,8 +371,7 @@ bd_open(struct open_file *f, ...)
disk.d_offset = 0;
if (disk_open(&disk, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
- BD(dev).bd_sectorsize, (BD(dev).bd_flags & BD_FLOPPY) ?
- DISK_F_NOCACHE: 0) == 0) {
+ BD(dev).bd_sectorsize) == 0) {
if (disk_ioctl(&disk, DIOCGMEDIASIZE, &size) == 0) {
size /= BD(dev).bd_sectorsize;
@@ -393,8 +382,7 @@ bd_open(struct open_file *f, ...)
}
return (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
- BD(dev).bd_sectorsize, (BD(dev).bd_flags & BD_FLOPPY) ?
- DISK_F_NOCACHE: 0));
+ BD(dev).bd_sectorsize));
}
static int
@@ -771,8 +759,7 @@ bd_getdev(struct i386_devdesc *d)
if (biosdev == -1) /* not a BIOS device */
return(-1);
if (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
- BD(dev).bd_sectorsize,(BD(dev).bd_flags & BD_FLOPPY) ?
- DISK_F_NOCACHE: 0) != 0) /* oops, not a viable device */
+ BD(dev).bd_sectorsize) != 0) /* oops, not a viable device */
return (-1);
else
disk_close(dev);
diff --git a/usr/src/boot/sys/boot/uboot/lib/disk.c b/usr/src/boot/sys/boot/uboot/lib/disk.c
index 22bec208a1..10b049049c 100644
--- a/usr/src/boot/sys/boot/uboot/lib/disk.c
+++ b/usr/src/boot/sys/boot/uboot/lib/disk.c
@@ -202,8 +202,7 @@ stor_opendev(struct disk_devdesc *dev)
}
SI(dev).opened++;
}
- return (disk_open(dev, SI(dev).blocks * SI(dev).bsize,
- SI(dev).bsize, 0));
+ return (disk_open(dev, SI(dev).blocks * SI(dev).bsize, SI(dev).bsize));
}
static int
diff --git a/usr/src/boot/sys/boot/usb/storage/umass_loader.c b/usr/src/boot/sys/boot/usb/storage/umass_loader.c
index 889c779c92..a4183424ba 100644
--- a/usr/src/boot/sys/boot/usb/storage/umass_loader.c
+++ b/usr/src/boot/sys/boot/usb/storage/umass_loader.c
@@ -116,7 +116,7 @@ umass_disk_open_sub(struct disk_devdesc *dev)
if (usb_msc_read_capacity(umass_uaa.device, 0, &nblock, &blocksize) != 0)
return (EINVAL);
- return (disk_open(dev, ((uint64_t)nblock + 1) * (uint64_t)blocksize, blocksize, 0));
+ return (disk_open(dev, ((uint64_t)nblock + 1) * (uint64_t)blocksize, blocksize));
}
static int
diff --git a/usr/src/boot/sys/boot/userboot/userboot/userboot_disk.c b/usr/src/boot/sys/boot/userboot/userboot/userboot_disk.c
index 156df63878..74a80885ae 100644
--- a/usr/src/boot/sys/boot/userboot/userboot/userboot_disk.c
+++ b/usr/src/boot/sys/boot/userboot/userboot/userboot_disk.c
@@ -132,7 +132,7 @@ userdisk_print(int verbose)
dev.d_slice = -1;
dev.d_partition = -1;
if (disk_open(&dev, ud_info[i].mediasize,
- ud_info[i].sectorsize, 0) == 0) {
+ ud_info[i].sectorsize) == 0) {
sprintf(line, " disk%d", i);
disk_print(&dev, line, verbose);
disk_close(&dev);
@@ -157,7 +157,7 @@ userdisk_open(struct open_file *f, ...)
return (EIO);
return (disk_open(dev, ud_info[dev->d_unit].mediasize,
- ud_info[dev->d_unit].sectorsize, 0));
+ ud_info[dev->d_unit].sectorsize));
}
static int