david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[block] Provide sandev_read() and sandev_write() as global symbols

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2017-04-26 20:00:10 +01:00
parent 2d79b20f2a
commit dd976cb50d
4 changed files with 83 additions and 50 deletions

View File

@ -181,8 +181,8 @@ static int int13_parse_eltorito ( struct san_device *sandev, void *scratch ) {
int rc; int rc;
/* Read boot record volume descriptor */ /* Read boot record volume descriptor */
if ( ( rc = sandev_rw ( sandev, ELTORITO_LBA, 1, if ( ( rc = sandev_read ( sandev, ELTORITO_LBA, 1,
virt_to_user ( boot ), block_read ) ) != 0 ) { virt_to_user ( boot ) ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read El Torito boot " DBGC ( sandev, "INT13 drive %02x could not read El Torito boot "
"record volume descriptor: %s\n", "record volume descriptor: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );
@ -227,8 +227,7 @@ static int int13_guess_geometry_hdd ( struct san_device *sandev, void *scratch,
int rc; int rc;
/* Read partition table */ /* Read partition table */
if ( ( rc = sandev_rw ( sandev, 0, 1, virt_to_user ( mbr ), if ( ( rc = sandev_read ( sandev, 0, 1, virt_to_user ( mbr ) ) ) != 0 ) {
block_read ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read " DBGC ( sandev, "INT13 drive %02x could not read "
"partition table to guess geometry: %s\n", "partition table to guess geometry: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );
@ -506,18 +505,16 @@ static int int13_get_last_status ( struct san_device *sandev,
* @v cl (bits 5:0) Sector number * @v cl (bits 5:0) Sector number
* @v dh Head number * @v dh Head number
* @v es:bx Data buffer * @v es:bx Data buffer
* @v block_rw Block read/write method * @v sandev_rw SAN device read/write method
* @ret status Status code * @ret status Status code
* @ret al Number of sectors read or written * @ret al Number of sectors read or written
*/ */
static int int13_rw_sectors ( struct san_device *sandev, static int int13_rw_sectors ( struct san_device *sandev,
struct i386_all_regs *ix86, struct i386_all_regs *ix86,
int ( * block_rw ) ( struct interface *control, int ( * sandev_rw ) ( struct san_device *sandev,
struct interface *data, uint64_t lba,
uint64_t lba, unsigned int count,
unsigned int count, userptr_t buffer ) ) {
userptr_t buffer,
size_t len ) ) {
struct int13_data *int13 = sandev->priv; struct int13_data *int13 = sandev->priv;
unsigned int cylinder, head, sector; unsigned int cylinder, head, sector;
unsigned long lba; unsigned long lba;
@ -555,7 +552,7 @@ static int int13_rw_sectors ( struct san_device *sandev,
count ); count );
/* Read from / write to block device */ /* Read from / write to block device */
if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_rw ) ) != 0 ){ if ( ( rc = sandev_rw ( sandev, lba, count, buffer ) ) != 0 ){
DBGC ( sandev, "INT13 drive %02x I/O failed: %s\n", DBGC ( sandev, "INT13 drive %02x I/O failed: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );
return -INT13_STATUS_READ_ERROR; return -INT13_STATUS_READ_ERROR;
@ -581,7 +578,7 @@ static int int13_read_sectors ( struct san_device *sandev,
struct i386_all_regs *ix86 ) { struct i386_all_regs *ix86 ) {
DBGC2 ( sandev, "Read: " ); DBGC2 ( sandev, "Read: " );
return int13_rw_sectors ( sandev, ix86, block_read ); return int13_rw_sectors ( sandev, ix86, sandev_read );
} }
/** /**
@ -601,7 +598,7 @@ static int int13_write_sectors ( struct san_device *sandev,
struct i386_all_regs *ix86 ) { struct i386_all_regs *ix86 ) {
DBGC2 ( sandev, "Write: " ); DBGC2 ( sandev, "Write: " );
return int13_rw_sectors ( sandev, ix86, block_write ); return int13_rw_sectors ( sandev, ix86, sandev_write );
} }
/** /**
@ -701,17 +698,15 @@ static int int13_extension_check ( struct san_device *sandev __unused,
* *
* @v sandev SAN device * @v sandev SAN device
* @v ds:si Disk address packet * @v ds:si Disk address packet
* @v block_rw Block read/write method * @v sandev_rw SAN device read/write method
* @ret status Status code * @ret status Status code
*/ */
static int int13_extended_rw ( struct san_device *sandev, static int int13_extended_rw ( struct san_device *sandev,
struct i386_all_regs *ix86, struct i386_all_regs *ix86,
int ( * block_rw ) ( struct interface *control, int ( * sandev_rw ) ( struct san_device *sandev,
struct interface *data, uint64_t lba,
uint64_t lba, unsigned int count,
unsigned int count, userptr_t buffer ) ) {
userptr_t buffer,
size_t len ) ) {
struct int13_disk_address addr; struct int13_disk_address addr;
uint8_t bufsize; uint8_t bufsize;
uint64_t lba; uint64_t lba;
@ -762,7 +757,7 @@ static int int13_extended_rw ( struct san_device *sandev,
DBGC2 ( sandev, " (count %ld)\n", count ); DBGC2 ( sandev, " (count %ld)\n", count );
/* Read from / write to block device */ /* Read from / write to block device */
if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_rw ) ) != 0 ){ if ( ( rc = sandev_rw ( sandev, lba, count, buffer ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x extended I/O failed: %s\n", DBGC ( sandev, "INT13 drive %02x extended I/O failed: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );
/* Record that no blocks were transferred successfully */ /* Record that no blocks were transferred successfully */
@ -787,7 +782,7 @@ static int int13_extended_read ( struct san_device *sandev,
struct i386_all_regs *ix86 ) { struct i386_all_regs *ix86 ) {
DBGC2 ( sandev, "Extended read: " ); DBGC2 ( sandev, "Extended read: " );
return int13_extended_rw ( sandev, ix86, block_read ); return int13_extended_rw ( sandev, ix86, sandev_read );
} }
/** /**
@ -801,7 +796,7 @@ static int int13_extended_write ( struct san_device *sandev,
struct i386_all_regs *ix86 ) { struct i386_all_regs *ix86 ) {
DBGC2 ( sandev, "Extended write: " ); DBGC2 ( sandev, "Extended write: " );
return int13_extended_rw ( sandev, ix86, block_write ); return int13_extended_rw ( sandev, ix86, sandev_write );
} }
/** /**
@ -1038,6 +1033,7 @@ static int int13_cdrom_read_boot_catalog ( struct san_device *sandev,
struct i386_all_regs *ix86 ) { struct i386_all_regs *ix86 ) {
struct int13_data *int13 = sandev->priv; struct int13_data *int13 = sandev->priv;
struct int13_cdrom_boot_catalog_command command; struct int13_cdrom_boot_catalog_command command;
unsigned int start;
int rc; int rc;
/* Read parameters from command packet */ /* Read parameters from command packet */
@ -1051,11 +1047,11 @@ static int int13_cdrom_read_boot_catalog ( struct san_device *sandev,
sandev->drive ); sandev->drive );
return -INT13_STATUS_INVALID; return -INT13_STATUS_INVALID;
} }
start = ( int13->boot_catalog + command.start );
/* Read from boot catalog */ /* Read from boot catalog */
if ( ( rc = sandev_rw ( sandev, ( int13->boot_catalog + command.start ), if ( ( rc = sandev_read ( sandev, start, command.count,
command.count, phys_to_user ( command.buffer ), phys_to_user ( command.buffer ) ) ) != 0 ) {
block_read ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read boot catalog: " DBGC ( sandev, "INT13 drive %02x could not read boot catalog: "
"%s\n", sandev->drive, strerror ( rc ) ); "%s\n", sandev->drive, strerror ( rc ) );
return -INT13_STATUS_READ_ERROR; return -INT13_STATUS_READ_ERROR;

View File

@ -577,12 +577,12 @@ int sandev_reset ( struct san_device *sandev ) {
* @v block_rw Block read/write method * @v block_rw Block read/write method
* @ret rc Return status code * @ret rc Return status code
*/ */
int sandev_rw ( struct san_device *sandev, uint64_t lba, static int sandev_rw ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer, unsigned int count, userptr_t buffer,
int ( * block_rw ) ( struct interface *control, int ( * block_rw ) ( struct interface *control,
struct interface *data, struct interface *data,
uint64_t lba, unsigned int count, uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) ) { userptr_t buffer, size_t len ) ) {
union san_command_params params; union san_command_params params;
unsigned int remaining; unsigned int remaining;
size_t frag_len; size_t frag_len;
@ -617,6 +617,46 @@ int sandev_rw ( struct san_device *sandev, uint64_t lba,
return 0; return 0;
} }
/**
* Read from SAN device
*
* @v sandev SAN device
* @v lba Starting logical block address
* @v count Number of logical blocks
* @v buffer Data buffer
* @ret rc Return status code
*/
int sandev_read ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer ) {
int rc;
/* Read from device */
if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_read ) ) != 0 )
return rc;
return 0;
}
/**
* Write to SAN device
*
* @v sandev SAN device
* @v lba Starting logical block address
* @v count Number of logical blocks
* @v buffer Data buffer
* @ret rc Return status code
*/
int sandev_write ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer ) {
int rc;
/* Write to device */
if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_write ) ) != 0 )
return rc;
return 0;
}
/** /**
* Describe SAN device * Describe SAN device
* *
@ -735,8 +775,8 @@ static int sandev_parse_iso9660 ( struct san_device *sandev ) {
} }
/* Read primary volume descriptor */ /* Read primary volume descriptor */
if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( scratch ), if ( ( rc = sandev_read ( sandev, lba, count,
block_read ) ) != 0 ) { virt_to_user ( scratch ) ) ) != 0 ) {
DBGC ( sandev, "SAN %#02x could not read ISO9660 primary" DBGC ( sandev, "SAN %#02x could not read ISO9660 primary"
"volume descriptor: %s\n", "volume descriptor: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );

View File

@ -236,12 +236,10 @@ static inline int sandev_needs_reopen ( struct san_device *sandev ) {
extern struct san_device * sandev_find ( unsigned int drive ); extern struct san_device * sandev_find ( unsigned int drive );
extern int sandev_reopen ( struct san_device *sandev ); extern int sandev_reopen ( struct san_device *sandev );
extern int sandev_reset ( struct san_device *sandev ); extern int sandev_reset ( struct san_device *sandev );
extern int sandev_rw ( struct san_device *sandev, uint64_t lba, extern int sandev_read ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer, unsigned int count, userptr_t buffer );
int ( * block_rw ) ( struct interface *control, extern int sandev_write ( struct san_device *sandev, uint64_t lba,
struct interface *data, unsigned int count, userptr_t buffer );
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) );
extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count, extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
size_t priv_size ); size_t priv_size );
extern int register_sandev ( struct san_device *sandev, unsigned int drive, extern int register_sandev ( struct san_device *sandev, unsigned int drive,

View File

@ -102,15 +102,14 @@ struct efi_block_data {
* @v lba Starting LBA * @v lba Starting LBA
* @v data Data buffer * @v data Data buffer
* @v len Size of buffer * @v len Size of buffer
* @v block_rw Block read/write method * @v sandev_rw SAN device read/write method
* @ret rc Return status code * @ret rc Return status code
*/ */
static int efi_block_rw ( struct san_device *sandev, uint64_t lba, static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
void *data, size_t len, void *data, size_t len,
int ( * block_rw ) ( struct interface *control, int ( * sandev_rw ) ( struct san_device *sandev,
struct interface *data, uint64_t lba, unsigned int count,
uint64_t lba, unsigned int count, userptr_t buffer ) ) {
userptr_t buffer, size_t len ) ){
struct efi_block_data *block = sandev->priv; struct efi_block_data *block = sandev->priv;
unsigned int count; unsigned int count;
int rc; int rc;
@ -124,8 +123,8 @@ static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
} }
/* Read from / write to block device */ /* Read from / write to block device */
if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( data ), if ( ( rc = sandev_rw ( sandev, lba, count,
block_rw ) ) != 0 ) { virt_to_user ( data ) ) ) != 0 ) {
DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n", DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n",
sandev->drive, strerror ( rc ) ); sandev->drive, strerror ( rc ) );
return rc; return rc;
@ -176,7 +175,7 @@ efi_block_io_read ( EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused,
DBGC2 ( sandev, "EFIBLK %#02x read LBA %#08llx to %p+%#08zx\n", DBGC2 ( sandev, "EFIBLK %#02x read LBA %#08llx to %p+%#08zx\n",
sandev->drive, lba, data, ( ( size_t ) len ) ); sandev->drive, lba, data, ( ( size_t ) len ) );
efi_snp_claim(); efi_snp_claim();
rc = efi_block_rw ( sandev, lba, data, len, block_read ); rc = efi_block_rw ( sandev, lba, data, len, sandev_read );
efi_snp_release(); efi_snp_release();
return EFIRC ( rc ); return EFIRC ( rc );
} }
@ -202,7 +201,7 @@ efi_block_io_write ( EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused,
DBGC2 ( sandev, "EFIBLK %#02x write LBA %#08llx from %p+%#08zx\n", DBGC2 ( sandev, "EFIBLK %#02x write LBA %#08llx from %p+%#08zx\n",
sandev->drive, lba, data, ( ( size_t ) len ) ); sandev->drive, lba, data, ( ( size_t ) len ) );
efi_snp_claim(); efi_snp_claim();
rc = efi_block_rw ( sandev, lba, data, len, block_write ); rc = efi_block_rw ( sandev, lba, data, len, sandev_write );
efi_snp_release(); efi_snp_release();
return EFIRC ( rc ); return EFIRC ( rc );
} }