Browse Source

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
dd976cb50d

+ 23
- 27
src/arch/x86/interface/pcbios/int13.c View File

181
 	int rc;
181
 	int rc;
182
 
182
 
183
 	/* Read boot record volume descriptor */
183
 	/* Read boot record volume descriptor */
184
-	if ( ( rc = sandev_rw ( sandev, ELTORITO_LBA, 1,
185
-				virt_to_user ( boot ), block_read ) ) != 0 ) {
184
+	if ( ( rc = sandev_read ( sandev, ELTORITO_LBA, 1,
185
+				  virt_to_user ( boot ) ) ) != 0 ) {
186
 		DBGC ( sandev, "INT13 drive %02x could not read El Torito boot "
186
 		DBGC ( sandev, "INT13 drive %02x could not read El Torito boot "
187
 		       "record volume descriptor: %s\n",
187
 		       "record volume descriptor: %s\n",
188
 		       sandev->drive, strerror ( rc ) );
188
 		       sandev->drive, strerror ( rc ) );
227
 	int rc;
227
 	int rc;
228
 
228
 
229
 	/* Read partition table */
229
 	/* Read partition table */
230
-	if ( ( rc = sandev_rw ( sandev, 0, 1, virt_to_user ( mbr ),
231
-				block_read ) ) != 0 ) {
230
+	if ( ( rc = sandev_read ( sandev, 0, 1, virt_to_user ( mbr ) ) ) != 0 ) {
232
 		DBGC ( sandev, "INT13 drive %02x could not read "
231
 		DBGC ( sandev, "INT13 drive %02x could not read "
233
 		       "partition table to guess geometry: %s\n",
232
 		       "partition table to guess geometry: %s\n",
234
 		       sandev->drive, strerror ( rc ) );
233
 		       sandev->drive, strerror ( rc ) );
506
  * @v cl (bits 5:0)	Sector number
505
  * @v cl (bits 5:0)	Sector number
507
  * @v dh		Head number
506
  * @v dh		Head number
508
  * @v es:bx		Data buffer
507
  * @v es:bx		Data buffer
509
- * @v block_rw		Block read/write method
508
+ * @v sandev_rw		SAN device read/write method
510
  * @ret status		Status code
509
  * @ret status		Status code
511
  * @ret al		Number of sectors read or written
510
  * @ret al		Number of sectors read or written
512
  */
511
  */
513
 static int int13_rw_sectors ( struct san_device *sandev,
512
 static int int13_rw_sectors ( struct san_device *sandev,
514
 			      struct i386_all_regs *ix86,
513
 			      struct i386_all_regs *ix86,
515
-			      int ( * block_rw ) ( struct interface *control,
516
-						   struct interface *data,
517
-						   uint64_t lba,
518
-						   unsigned int count,
519
-						   userptr_t buffer,
520
-						   size_t len ) ) {
514
+			      int ( * sandev_rw ) ( struct san_device *sandev,
515
+						    uint64_t lba,
516
+						    unsigned int count,
517
+						    userptr_t buffer ) ) {
521
 	struct int13_data *int13 = sandev->priv;
518
 	struct int13_data *int13 = sandev->priv;
522
 	unsigned int cylinder, head, sector;
519
 	unsigned int cylinder, head, sector;
523
 	unsigned long lba;
520
 	unsigned long lba;
555
 		count );
552
 		count );
556
 
553
 
557
 	/* Read from / write to block device */
554
 	/* Read from / write to block device */
558
-	if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_rw ) ) != 0 ){
555
+	if ( ( rc = sandev_rw ( sandev, lba, count, buffer ) ) != 0 ){
559
 		DBGC ( sandev, "INT13 drive %02x I/O failed: %s\n",
556
 		DBGC ( sandev, "INT13 drive %02x I/O failed: %s\n",
560
 		       sandev->drive, strerror ( rc ) );
557
 		       sandev->drive, strerror ( rc ) );
561
 		return -INT13_STATUS_READ_ERROR;
558
 		return -INT13_STATUS_READ_ERROR;
581
 				struct i386_all_regs *ix86 ) {
578
 				struct i386_all_regs *ix86 ) {
582
 
579
 
583
 	DBGC2 ( sandev, "Read: " );
580
 	DBGC2 ( sandev, "Read: " );
584
-	return int13_rw_sectors ( sandev, ix86, block_read );
581
+	return int13_rw_sectors ( sandev, ix86, sandev_read );
585
 }
582
 }
586
 
583
 
587
 /**
584
 /**
601
 				 struct i386_all_regs *ix86 ) {
598
 				 struct i386_all_regs *ix86 ) {
602
 
599
 
603
 	DBGC2 ( sandev, "Write: " );
600
 	DBGC2 ( sandev, "Write: " );
604
-	return int13_rw_sectors ( sandev, ix86, block_write );
601
+	return int13_rw_sectors ( sandev, ix86, sandev_write );
605
 }
602
 }
606
 
603
 
607
 /**
604
 /**
701
  *
698
  *
702
  * @v sandev		SAN device
699
  * @v sandev		SAN device
703
  * @v ds:si		Disk address packet
700
  * @v ds:si		Disk address packet
704
- * @v block_rw		Block read/write method
701
+ * @v sandev_rw		SAN device read/write method
705
  * @ret status		Status code
702
  * @ret status		Status code
706
  */
703
  */
707
 static int int13_extended_rw ( struct san_device *sandev,
704
 static int int13_extended_rw ( struct san_device *sandev,
708
 			       struct i386_all_regs *ix86,
705
 			       struct i386_all_regs *ix86,
709
-			       int ( * block_rw ) ( struct interface *control,
710
-						    struct interface *data,
711
-						    uint64_t lba,
712
-						    unsigned int count,
713
-						    userptr_t buffer,
714
-						    size_t len ) ) {
706
+			       int ( * sandev_rw ) ( struct san_device *sandev,
707
+						     uint64_t lba,
708
+						     unsigned int count,
709
+						     userptr_t buffer ) ) {
715
 	struct int13_disk_address addr;
710
 	struct int13_disk_address addr;
716
 	uint8_t bufsize;
711
 	uint8_t bufsize;
717
 	uint64_t lba;
712
 	uint64_t lba;
762
 	DBGC2 ( sandev, " (count %ld)\n", count );
757
 	DBGC2 ( sandev, " (count %ld)\n", count );
763
 
758
 
764
 	/* Read from / write to block device */
759
 	/* Read from / write to block device */
765
-	if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_rw ) ) != 0 ){
760
+	if ( ( rc = sandev_rw ( sandev, lba, count, buffer ) ) != 0 ) {
766
 		DBGC ( sandev, "INT13 drive %02x extended I/O failed: %s\n",
761
 		DBGC ( sandev, "INT13 drive %02x extended I/O failed: %s\n",
767
 		       sandev->drive, strerror ( rc ) );
762
 		       sandev->drive, strerror ( rc ) );
768
 		/* Record that no blocks were transferred successfully */
763
 		/* Record that no blocks were transferred successfully */
787
 				 struct i386_all_regs *ix86 ) {
782
 				 struct i386_all_regs *ix86 ) {
788
 
783
 
789
 	DBGC2 ( sandev, "Extended read: " );
784
 	DBGC2 ( sandev, "Extended read: " );
790
-	return int13_extended_rw ( sandev, ix86, block_read );
785
+	return int13_extended_rw ( sandev, ix86, sandev_read );
791
 }
786
 }
792
 
787
 
793
 /**
788
 /**
801
 				  struct i386_all_regs *ix86 ) {
796
 				  struct i386_all_regs *ix86 ) {
802
 
797
 
803
 	DBGC2 ( sandev, "Extended write: " );
798
 	DBGC2 ( sandev, "Extended write: " );
804
-	return int13_extended_rw ( sandev, ix86, block_write );
799
+	return int13_extended_rw ( sandev, ix86, sandev_write );
805
 }
800
 }
806
 
801
 
807
 /**
802
 /**
1038
 					   struct i386_all_regs *ix86 ) {
1033
 					   struct i386_all_regs *ix86 ) {
1039
 	struct int13_data *int13 = sandev->priv;
1034
 	struct int13_data *int13 = sandev->priv;
1040
 	struct int13_cdrom_boot_catalog_command command;
1035
 	struct int13_cdrom_boot_catalog_command command;
1036
+	unsigned int start;
1041
 	int rc;
1037
 	int rc;
1042
 
1038
 
1043
 	/* Read parameters from command packet */
1039
 	/* Read parameters from command packet */
1051
 		       sandev->drive );
1047
 		       sandev->drive );
1052
 		return -INT13_STATUS_INVALID;
1048
 		return -INT13_STATUS_INVALID;
1053
 	}
1049
 	}
1050
+	start = ( int13->boot_catalog + command.start );
1054
 
1051
 
1055
 	/* Read from boot catalog */
1052
 	/* Read from boot catalog */
1056
-	if ( ( rc = sandev_rw ( sandev, ( int13->boot_catalog + command.start ),
1057
-				command.count, phys_to_user ( command.buffer ),
1058
-				block_read ) ) != 0 ) {
1053
+	if ( ( rc = sandev_read ( sandev, start, command.count,
1054
+				  phys_to_user ( command.buffer ) ) ) != 0 ) {
1059
 		DBGC ( sandev, "INT13 drive %02x could not read boot catalog: "
1055
 		DBGC ( sandev, "INT13 drive %02x could not read boot catalog: "
1060
 		       "%s\n", sandev->drive, strerror ( rc ) );
1056
 		       "%s\n", sandev->drive, strerror ( rc ) );
1061
 		return -INT13_STATUS_READ_ERROR;
1057
 		return -INT13_STATUS_READ_ERROR;

+ 48
- 8
src/core/sanboot.c View File

577
  * @v block_rw		Block read/write method
577
  * @v block_rw		Block read/write method
578
  * @ret rc		Return status code
578
  * @ret rc		Return status code
579
  */
579
  */
580
-int sandev_rw ( struct san_device *sandev, uint64_t lba,
581
-		unsigned int count, userptr_t buffer,
582
-		int ( * block_rw ) ( struct interface *control,
583
-				     struct interface *data,
584
-				     uint64_t lba, unsigned int count,
585
-				     userptr_t buffer, size_t len ) ) {
580
+static int sandev_rw ( struct san_device *sandev, uint64_t lba,
581
+		       unsigned int count, userptr_t buffer,
582
+		       int ( * block_rw ) ( struct interface *control,
583
+					    struct interface *data,
584
+					    uint64_t lba, unsigned int count,
585
+					    userptr_t buffer, size_t len ) ) {
586
 	union san_command_params params;
586
 	union san_command_params params;
587
 	unsigned int remaining;
587
 	unsigned int remaining;
588
 	size_t frag_len;
588
 	size_t frag_len;
617
 	return 0;
617
 	return 0;
618
 }
618
 }
619
 
619
 
620
+/**
621
+ * Read from SAN device
622
+ *
623
+ * @v sandev		SAN device
624
+ * @v lba		Starting logical block address
625
+ * @v count		Number of logical blocks
626
+ * @v buffer		Data buffer
627
+ * @ret rc		Return status code
628
+ */
629
+int sandev_read ( struct san_device *sandev, uint64_t lba,
630
+		  unsigned int count, userptr_t buffer ) {
631
+	int rc;
632
+
633
+	/* Read from device */
634
+	if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_read ) ) != 0 )
635
+		return rc;
636
+
637
+	return 0;
638
+}
639
+
640
+/**
641
+ * Write to SAN device
642
+ *
643
+ * @v sandev		SAN device
644
+ * @v lba		Starting logical block address
645
+ * @v count		Number of logical blocks
646
+ * @v buffer		Data buffer
647
+ * @ret rc		Return status code
648
+ */
649
+int sandev_write ( struct san_device *sandev, uint64_t lba,
650
+		   unsigned int count, userptr_t buffer ) {
651
+	int rc;
652
+
653
+	/* Write to device */
654
+	if ( ( rc = sandev_rw ( sandev, lba, count, buffer, block_write ) ) != 0 )
655
+		return rc;
656
+
657
+	return 0;
658
+}
659
+
620
 /**
660
 /**
621
  * Describe SAN device
661
  * Describe SAN device
622
  *
662
  *
735
 	}
775
 	}
736
 
776
 
737
 	/* Read primary volume descriptor */
777
 	/* Read primary volume descriptor */
738
-	if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( scratch ),
739
-				block_read ) ) != 0 ) {
778
+	if ( ( rc = sandev_read ( sandev, lba, count,
779
+				  virt_to_user ( scratch ) ) ) != 0 ) {
740
 		DBGC ( sandev, "SAN %#02x could not read ISO9660 primary"
780
 		DBGC ( sandev, "SAN %#02x could not read ISO9660 primary"
741
 		       "volume descriptor: %s\n",
781
 		       "volume descriptor: %s\n",
742
 		       sandev->drive, strerror ( rc ) );
782
 		       sandev->drive, strerror ( rc ) );

+ 4
- 6
src/include/ipxe/sanboot.h View File

236
 extern struct san_device * sandev_find ( unsigned int drive );
236
 extern struct san_device * sandev_find ( unsigned int drive );
237
 extern int sandev_reopen ( struct san_device *sandev );
237
 extern int sandev_reopen ( struct san_device *sandev );
238
 extern int sandev_reset ( struct san_device *sandev );
238
 extern int sandev_reset ( struct san_device *sandev );
239
-extern int sandev_rw ( struct san_device *sandev, uint64_t lba,
240
-		       unsigned int count, userptr_t buffer,
241
-		       int ( * block_rw ) ( struct interface *control,
242
-					    struct interface *data,
243
-					    uint64_t lba, unsigned int count,
244
-					    userptr_t buffer, size_t len ) );
239
+extern int sandev_read ( struct san_device *sandev, uint64_t lba,
240
+			 unsigned int count, userptr_t buffer );
241
+extern int sandev_write ( struct san_device *sandev, uint64_t lba,
242
+			  unsigned int count, userptr_t buffer );
245
 extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
243
 extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
246
 					  size_t priv_size );
244
 					  size_t priv_size );
247
 extern int register_sandev ( struct san_device *sandev, unsigned int drive,
245
 extern int register_sandev ( struct san_device *sandev, unsigned int drive,

+ 8
- 9
src/interface/efi/efi_block.c View File

102
  * @v lba		Starting LBA
102
  * @v lba		Starting LBA
103
  * @v data		Data buffer
103
  * @v data		Data buffer
104
  * @v len		Size of buffer
104
  * @v len		Size of buffer
105
- * @v block_rw		Block read/write method
105
+ * @v sandev_rw		SAN device read/write method
106
  * @ret rc		Return status code
106
  * @ret rc		Return status code
107
  */
107
  */
108
 static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
108
 static int efi_block_rw ( struct san_device *sandev, uint64_t lba,
109
 			  void *data, size_t len,
109
 			  void *data, size_t len,
110
-			  int ( * block_rw ) ( struct interface *control,
111
-					       struct interface *data,
112
-					       uint64_t lba, unsigned int count,
113
-					       userptr_t buffer, size_t len ) ){
110
+			  int ( * sandev_rw ) ( struct san_device *sandev,
111
+						uint64_t lba, unsigned int count,
112
+						userptr_t buffer ) ) {
114
 	struct efi_block_data *block = sandev->priv;
113
 	struct efi_block_data *block = sandev->priv;
115
 	unsigned int count;
114
 	unsigned int count;
116
 	int rc;
115
 	int rc;
124
 	}
123
 	}
125
 
124
 
126
 	/* Read from / write to block device */
125
 	/* Read from / write to block device */
127
-	if ( ( rc = sandev_rw ( sandev, lba, count, virt_to_user ( data ),
128
-				block_rw ) ) != 0 ) {
126
+	if ( ( rc = sandev_rw ( sandev, lba, count,
127
+				virt_to_user ( data ) ) ) != 0 ) {
129
 		DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n",
128
 		DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n",
130
 		       sandev->drive, strerror ( rc ) );
129
 		       sandev->drive, strerror ( rc ) );
131
 		return rc;
130
 		return rc;
176
 	DBGC2 ( sandev, "EFIBLK %#02x read LBA %#08llx to %p+%#08zx\n",
175
 	DBGC2 ( sandev, "EFIBLK %#02x read LBA %#08llx to %p+%#08zx\n",
177
 		sandev->drive, lba, data, ( ( size_t ) len ) );
176
 		sandev->drive, lba, data, ( ( size_t ) len ) );
178
 	efi_snp_claim();
177
 	efi_snp_claim();
179
-	rc = efi_block_rw ( sandev, lba, data, len, block_read );
178
+	rc = efi_block_rw ( sandev, lba, data, len, sandev_read );
180
 	efi_snp_release();
179
 	efi_snp_release();
181
 	return EFIRC ( rc );
180
 	return EFIRC ( rc );
182
 }
181
 }
202
 	DBGC2 ( sandev, "EFIBLK %#02x write LBA %#08llx from %p+%#08zx\n",
201
 	DBGC2 ( sandev, "EFIBLK %#02x write LBA %#08llx from %p+%#08zx\n",
203
 		sandev->drive, lba, data, ( ( size_t ) len ) );
202
 		sandev->drive, lba, data, ( ( size_t ) len ) );
204
 	efi_snp_claim();
203
 	efi_snp_claim();
205
-	rc = efi_block_rw ( sandev, lba, data, len, block_write );
204
+	rc = efi_block_rw ( sandev, lba, data, len, sandev_write );
206
 	efi_snp_release();
205
 	efi_snp_release();
207
 	return EFIRC ( rc );
206
 	return EFIRC ( rc );
208
 }
207
 }

Loading…
Cancel
Save