[blockdev] Move block device operations to structure block_device_operations
authorLaurent Vivier <Laurent.Vivier@bull.net>
Wed, 19 Nov 2008 16:31:07 +0000 (17:31 +0100)
committerMichael Brown <mcb30@etherboot.org>
Wed, 19 Nov 2008 20:04:43 +0000 (20:04 +0000)
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
src/arch/i386/interface/pcbios/int13.c
src/drivers/block/ata.c
src/drivers/block/ramdisk.c
src/drivers/block/scsi.c
src/include/gpxe/blockdev.h

index a18039e..2e9de5c 100644 (file)
@@ -144,7 +144,7 @@ static int int13_rw_sectors ( struct int13_drive *drive,
 static int int13_read_sectors ( struct int13_drive *drive,
                                struct i386_all_regs *ix86 ) {
        DBG ( "Read: " );
-       return int13_rw_sectors ( drive, ix86, drive->blockdev->read );
+       return int13_rw_sectors ( drive, ix86, drive->blockdev->op->read );
 }
 
 /**
@@ -163,7 +163,7 @@ static int int13_read_sectors ( struct int13_drive *drive,
 static int int13_write_sectors ( struct int13_drive *drive,
                                 struct i386_all_regs *ix86 ) {
        DBG ( "Write: " );
-       return int13_rw_sectors ( drive, ix86, drive->blockdev->write );
+       return int13_rw_sectors ( drive, ix86, drive->blockdev->op->write );
 }
 
 /**
@@ -275,7 +275,7 @@ static int int13_extended_rw ( struct int13_drive *drive,
 static int int13_extended_read ( struct int13_drive *drive,
                                 struct i386_all_regs *ix86 ) {
        DBG ( "Extended read: " );
-       return int13_extended_rw ( drive, ix86, drive->blockdev->read );
+       return int13_extended_rw ( drive, ix86, drive->blockdev->op->read );
 }
 
 /**
@@ -288,7 +288,7 @@ static int int13_extended_read ( struct int13_drive *drive,
 static int int13_extended_write ( struct int13_drive *drive,
                                  struct i386_all_regs *ix86 ) {
        DBG ( "Extended write: " );
-       return int13_extended_rw ( drive, ix86, drive->blockdev->write );
+       return int13_extended_rw ( drive, ix86, drive->blockdev->op->write );
 }
 
 /**
@@ -488,8 +488,8 @@ static void guess_int13_geometry ( struct int13_drive *drive ) {
        /* Scan through partition table and modify guesses for heads
         * and sectors_per_track if we find any used partitions.
         */
-       if ( drive->blockdev->read ( drive->blockdev, 0, 1,
-                                    virt_to_user ( &mbr ) ) == 0 ) {
+       if ( drive->blockdev->op->read ( drive->blockdev, 0, 1,
+                                        virt_to_user ( &mbr ) ) == 0 ) {
                for ( i = 0 ; i < 4 ; i++ ) {
                        partition = &mbr.partitions[i];
                        if ( ! partition->type )
index 555a5f6..c21d2f6 100644 (file)
@@ -139,6 +139,11 @@ static int ata_identify ( struct block_device *blockdev ) {
        return 0;
 }
 
+static struct block_device_operations ata_operations = {
+       .read   = ata_read,
+       .write  = ata_write
+};
+
 /**
  * Initialise ATA device
  *
@@ -153,7 +158,6 @@ static int ata_identify ( struct block_device *blockdev ) {
  */
 int init_atadev ( struct ata_device *ata ) {
        /** Fill in read and write methods, and get device capacity */
-       ata->blockdev.read = ata_read;
-       ata->blockdev.write = ata_write;
+       ata->blockdev.op = &ata_operations;
        return ata_identify ( &ata->blockdev );
 }
index b5324bf..5091199 100644 (file)
@@ -75,6 +75,11 @@ static int ramdisk_write ( struct block_device *blockdev, uint64_t block,
        return 0;
 }
 
+static struct block_device_operations ramdisk_operations = {
+       .read   = ramdisk_read,
+       .write  = ramdisk_write
+};
+
 int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
                   unsigned int blksize ) {
        
@@ -82,8 +87,7 @@ int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
                blksize = 512;
 
        ramdisk->data = data;
-       ramdisk->blockdev.read = ramdisk_read;
-       ramdisk->blockdev.write = ramdisk_write;
+       ramdisk->blockdev.op = &ramdisk_operations;
        ramdisk->blockdev.blksize = blksize;
        ramdisk->blockdev.blocks = ( len / blksize );
 
index 9651583..9ff47f8 100644 (file)
@@ -228,6 +228,16 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
        return 0;
 }
 
+static struct block_device_operations scsi_operations_16 = {
+       .read   = scsi_read_16,
+       .write  = scsi_write_16,
+};
+
+static struct block_device_operations scsi_operations_10 = {
+       .read   = scsi_read_10,
+       .write  = scsi_write_10,
+};
+
 /**
  * Initialise SCSI device
  *
@@ -250,8 +260,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
        scsi_read_capacity_10 ( &scsi->blockdev );
 
        /* Try READ CAPACITY (10), which is a mandatory command, first. */
-       scsi->blockdev.read = scsi_read_10;
-       scsi->blockdev.write = scsi_write_10;
+       scsi->blockdev.op = &scsi_operations_10;
        if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
                return rc;
 
@@ -261,8 +270,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
         * mandatory, so we can't just use it straight off.
         */
        if ( scsi->blockdev.blocks == 0 ) {
-               scsi->blockdev.read = scsi_read_16;
-               scsi->blockdev.write = scsi_write_16;
+               scsi->blockdev.op = &scsi_operations_16;
                if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
                        return rc;
        }
index 467ed1d..8222984 100644 (file)
 
 #include <gpxe/uaccess.h>
 
-/** A block device */
-struct block_device {
-       /** Block size */
-       size_t blksize;
-       /** Total number of blocks */
-       uint64_t blocks;
+struct block_device;
+
+/** Block device operations */
+struct block_device_operations {
        /**
         * Read block
         *
@@ -40,4 +38,14 @@ struct block_device {
                          unsigned long count, userptr_t buffer );
 };
 
+/** A block device */
+struct block_device {
+       /** Block device operations */
+       struct block_device_operations *op;
+       /** Block size */
+       size_t blksize;
+       /** Total number of blocks */
+       uint64_t blocks;
+};
+
 #endif /* _GPXE_BLOCKDEV_H */