Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[blockdev] Move block device operations to structure block_device_ope…
…rations

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
  • Loading branch information
Laurent Vivier authored and Michael Brown committed Nov 19, 2008
1 parent b48f37e commit a2686a5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/arch/i386/interface/pcbios/int13.c
Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

/**
Expand Down Expand Up @@ -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 )
Expand Down
8 changes: 6 additions & 2 deletions src/drivers/block/ata.c
Expand Up @@ -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
*
Expand All @@ -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 );
}
8 changes: 6 additions & 2 deletions src/drivers/block/ramdisk.c
Expand Up @@ -75,15 +75,19 @@ 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 ) {

if ( ! blksize )
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 );

Expand Down
16 changes: 12 additions & 4 deletions src/drivers/block/scsi.c
Expand Up @@ -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
*
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down
20 changes: 14 additions & 6 deletions src/include/gpxe/blockdev.h
Expand Up @@ -10,12 +10,10 @@

#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
*
Expand All @@ -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 */

0 comments on commit a2686a5

Please sign in to comment.