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;
/* Read boot record volume descriptor */
if ( ( rc = sandev_rw ( sandev, ELTORITO_LBA, 1,
virt_to_user ( boot ), block_read ) ) != 0 ) {
if ( ( rc = sandev_read ( sandev, ELTORITO_LBA, 1,
virt_to_user ( boot ) ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read El Torito boot "
"record volume descriptor: %s\n",
sandev->drive, strerror ( rc ) );
@ -227,8 +227,7 @@ static int int13_guess_geometry_hdd ( struct san_device *sandev, void *scratch,
int rc;
/* Read partition table */
if ( ( rc = sandev_rw ( sandev, 0, 1, virt_to_user ( mbr ),
block_read ) ) != 0 ) {
if ( ( rc = sandev_read ( sandev, 0, 1, virt_to_user ( mbr ) ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read "
"partition table to guess geometry: %s\n",
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 dh Head number
* @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 al Number of sectors read or written
*/
static int int13_rw_sectors ( struct san_device *sandev,
struct i386_all_regs *ix86,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba,
unsigned int count,
userptr_t buffer,
size_t len ) ) {
int ( * sandev_rw ) ( struct san_device *sandev,
uint64_t lba,
unsigned int count,
userptr_t buffer ) ) {
struct int13_data *int13 = sandev->priv;
unsigned int cylinder, head, sector;
unsigned long lba;
@ -555,7 +552,7 @@ static int int13_rw_sectors ( struct san_device *sandev,
count );
/* 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",
sandev->drive, strerror ( rc ) );
return -INT13_STATUS_READ_ERROR;
@ -581,7 +578,7 @@ static int int13_read_sectors ( struct san_device *sandev,
struct i386_all_regs *ix86 ) {
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 ) {
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 ds:si Disk address packet
* @v block_rw Block read/write method
* @v sandev_rw SAN device read/write method
* @ret status Status code
*/
static int int13_extended_rw ( struct san_device *sandev,
struct i386_all_regs *ix86,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba,
unsigned int count,
userptr_t buffer,
size_t len ) ) {
int ( * sandev_rw ) ( struct san_device *sandev,
uint64_t lba,
unsigned int count,
userptr_t buffer ) ) {
struct int13_disk_address addr;
uint8_t bufsize;
uint64_t lba;
@ -762,7 +757,7 @@ static int int13_extended_rw ( struct san_device *sandev,
DBGC2 ( sandev, " (count %ld)\n", count );
/* 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",
sandev->drive, strerror ( rc ) );
/* 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 ) {
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 ) {
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 int13_data *int13 = sandev->priv;
struct int13_cdrom_boot_catalog_command command;
unsigned int start;
int rc;
/* Read parameters from command packet */
@ -1051,11 +1047,11 @@ static int int13_cdrom_read_boot_catalog ( struct san_device *sandev,
sandev->drive );
return -INT13_STATUS_INVALID;
}
start = ( int13->boot_catalog + command.start );
/* Read from boot catalog */
if ( ( rc = sandev_rw ( sandev, ( int13->boot_catalog + command.start ),
command.count, phys_to_user ( command.buffer ),
block_read ) ) != 0 ) {
if ( ( rc = sandev_read ( sandev, start, command.count,
phys_to_user ( command.buffer ) ) ) != 0 ) {
DBGC ( sandev, "INT13 drive %02x could not read boot catalog: "
"%s\n", sandev->drive, strerror ( rc ) );
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
* @ret rc Return status code
*/
int sandev_rw ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) ) {
static int sandev_rw ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) ) {
union san_command_params params;
unsigned int remaining;
size_t frag_len;
@ -617,6 +617,46 @@ int sandev_rw ( struct san_device *sandev, uint64_t lba,
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
*
@ -735,8 +775,8 @@ static int sandev_parse_iso9660 ( struct san_device *sandev ) {
}
/* Read primary volume descriptor */
if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( scratch ),
block_read ) ) != 0 ) {
if ( ( rc = sandev_read ( sandev, lba, count,
virt_to_user ( scratch ) ) ) != 0 ) {
DBGC ( sandev, "SAN %#02x could not read ISO9660 primary"
"volume descriptor: %s\n",
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 int sandev_reopen ( struct san_device *sandev );
extern int sandev_reset ( struct san_device *sandev );
extern int sandev_rw ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) );
extern int sandev_read ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer );
extern int sandev_write ( struct san_device *sandev, uint64_t lba,
unsigned int count, userptr_t buffer );
extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
size_t priv_size );
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 data Data 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
*/
static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
void *data, size_t len,
int ( * block_rw ) ( struct interface *control,
struct interface *data,
uint64_t lba, unsigned int count,
userptr_t buffer, size_t len ) ){
int ( * sandev_rw ) ( struct san_device *sandev,
uint64_t lba, unsigned int count,
userptr_t buffer ) ) {
struct efi_block_data *block = sandev->priv;
unsigned int count;
int rc;
@ -124,8 +123,8 @@ static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
}
/* Read from / write to block device */
if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( data ),
block_rw ) ) != 0 ) {
if ( ( rc = sandev_rw ( sandev, lba, count,
virt_to_user ( data ) ) ) != 0 ) {
DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n",
sandev->drive, strerror ( 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",
sandev->drive, lba, data, ( ( size_t ) len ) );
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();
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",
sandev->drive, lba, data, ( ( size_t ) len ) );
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();
return EFIRC ( rc );
}