Quellcode durchsuchen

[blockdev] Move block device operations to structure block_device_operations

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
tags/v0.9.6
Laurent Vivier vor 16 Jahren
Ursprung
Commit
a2686a55c4

+ 6
- 6
src/arch/i386/interface/pcbios/int13.c Datei anzeigen

@@ -144,7 +144,7 @@ static int int13_rw_sectors ( struct int13_drive *drive,
144 144
 static int int13_read_sectors ( struct int13_drive *drive,
145 145
 				struct i386_all_regs *ix86 ) {
146 146
 	DBG ( "Read: " );
147
-	return int13_rw_sectors ( drive, ix86, drive->blockdev->read );
147
+	return int13_rw_sectors ( drive, ix86, drive->blockdev->op->read );
148 148
 }
149 149
 
150 150
 /**
@@ -163,7 +163,7 @@ static int int13_read_sectors ( struct int13_drive *drive,
163 163
 static int int13_write_sectors ( struct int13_drive *drive,
164 164
 				 struct i386_all_regs *ix86 ) {
165 165
 	DBG ( "Write: " );
166
-	return int13_rw_sectors ( drive, ix86, drive->blockdev->write );
166
+	return int13_rw_sectors ( drive, ix86, drive->blockdev->op->write );
167 167
 }
168 168
 
169 169
 /**
@@ -275,7 +275,7 @@ static int int13_extended_rw ( struct int13_drive *drive,
275 275
 static int int13_extended_read ( struct int13_drive *drive,
276 276
 				 struct i386_all_regs *ix86 ) {
277 277
 	DBG ( "Extended read: " );
278
-	return int13_extended_rw ( drive, ix86, drive->blockdev->read );
278
+	return int13_extended_rw ( drive, ix86, drive->blockdev->op->read );
279 279
 }
280 280
 
281 281
 /**
@@ -288,7 +288,7 @@ static int int13_extended_read ( struct int13_drive *drive,
288 288
 static int int13_extended_write ( struct int13_drive *drive,
289 289
 				  struct i386_all_regs *ix86 ) {
290 290
 	DBG ( "Extended write: " );
291
-	return int13_extended_rw ( drive, ix86, drive->blockdev->write );
291
+	return int13_extended_rw ( drive, ix86, drive->blockdev->op->write );
292 292
 }
293 293
 
294 294
 /**
@@ -488,8 +488,8 @@ static void guess_int13_geometry ( struct int13_drive *drive ) {
488 488
 	/* Scan through partition table and modify guesses for heads
489 489
 	 * and sectors_per_track if we find any used partitions.
490 490
 	 */
491
-	if ( drive->blockdev->read ( drive->blockdev, 0, 1,
492
-				     virt_to_user ( &mbr ) ) == 0 ) {
491
+	if ( drive->blockdev->op->read ( drive->blockdev, 0, 1,
492
+				         virt_to_user ( &mbr ) ) == 0 ) {
493 493
 		for ( i = 0 ; i < 4 ; i++ ) {
494 494
 			partition = &mbr.partitions[i];
495 495
 			if ( ! partition->type )

+ 6
- 2
src/drivers/block/ata.c Datei anzeigen

@@ -139,6 +139,11 @@ static int ata_identify ( struct block_device *blockdev ) {
139 139
 	return 0;
140 140
 }
141 141
 
142
+static struct block_device_operations ata_operations = {
143
+	.read	= ata_read,
144
+	.write	= ata_write
145
+};
146
+
142 147
 /**
143 148
  * Initialise ATA device
144 149
  *
@@ -153,7 +158,6 @@ static int ata_identify ( struct block_device *blockdev ) {
153 158
  */
154 159
 int init_atadev ( struct ata_device *ata ) {
155 160
 	/** Fill in read and write methods, and get device capacity */
156
-	ata->blockdev.read = ata_read;
157
-	ata->blockdev.write = ata_write;
161
+	ata->blockdev.op = &ata_operations;
158 162
 	return ata_identify ( &ata->blockdev );
159 163
 }

+ 6
- 2
src/drivers/block/ramdisk.c Datei anzeigen

@@ -75,6 +75,11 @@ static int ramdisk_write ( struct block_device *blockdev, uint64_t block,
75 75
 	return 0;
76 76
 }
77 77
 
78
+static struct block_device_operations ramdisk_operations = {
79
+	.read	= ramdisk_read,
80
+	.write	= ramdisk_write
81
+};
82
+
78 83
 int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
79 84
 		   unsigned int blksize ) {
80 85
 	
@@ -82,8 +87,7 @@ int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
82 87
 		blksize = 512;
83 88
 
84 89
 	ramdisk->data = data;
85
-	ramdisk->blockdev.read = ramdisk_read;
86
-	ramdisk->blockdev.write = ramdisk_write;
90
+	ramdisk->blockdev.op = &ramdisk_operations;
87 91
 	ramdisk->blockdev.blksize = blksize;
88 92
 	ramdisk->blockdev.blocks = ( len / blksize );
89 93
 

+ 12
- 4
src/drivers/block/scsi.c Datei anzeigen

@@ -228,6 +228,16 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
228 228
 	return 0;
229 229
 }
230 230
 
231
+static struct block_device_operations scsi_operations_16 = {
232
+	.read	= scsi_read_16,
233
+	.write	= scsi_write_16,
234
+};
235
+
236
+static struct block_device_operations scsi_operations_10 = {
237
+	.read	= scsi_read_10,
238
+	.write	= scsi_write_10,
239
+};
240
+
231 241
 /**
232 242
  * Initialise SCSI device
233 243
  *
@@ -250,8 +260,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
250 260
 	scsi_read_capacity_10 ( &scsi->blockdev );
251 261
 
252 262
 	/* Try READ CAPACITY (10), which is a mandatory command, first. */
253
-	scsi->blockdev.read = scsi_read_10;
254
-	scsi->blockdev.write = scsi_write_10;
263
+	scsi->blockdev.op = &scsi_operations_10;
255 264
 	if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
256 265
 		return rc;
257 266
 
@@ -261,8 +270,7 @@ int init_scsidev ( struct scsi_device *scsi ) {
261 270
 	 * mandatory, so we can't just use it straight off.
262 271
 	 */
263 272
 	if ( scsi->blockdev.blocks == 0 ) {
264
-		scsi->blockdev.read = scsi_read_16;
265
-		scsi->blockdev.write = scsi_write_16;
273
+		scsi->blockdev.op = &scsi_operations_16;
266 274
 		if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
267 275
 			return rc;
268 276
 	}

+ 14
- 6
src/include/gpxe/blockdev.h Datei anzeigen

@@ -10,12 +10,10 @@
10 10
 
11 11
 #include <gpxe/uaccess.h>
12 12
 
13
-/** A block device */
14
-struct block_device {
15
-	/** Block size */
16
-	size_t blksize;
17
-	/** Total number of blocks */
18
-	uint64_t blocks;
13
+struct block_device;
14
+
15
+/** Block device operations */
16
+struct block_device_operations {
19 17
 	/**
20 18
 	 * Read block
21 19
 	 *
@@ -40,4 +38,14 @@ struct block_device {
40 38
 			  unsigned long count, userptr_t buffer );
41 39
 };
42 40
 
41
+/** A block device */
42
+struct block_device {
43
+	/** Block device operations */
44
+	struct block_device_operations *op;
45
+	/** Block size */
46
+	size_t blksize;
47
+	/** Total number of blocks */
48
+	uint64_t blocks;
49
+};
50
+
43 51
 #endif /* _GPXE_BLOCKDEV_H */

Laden…
Abbrechen
Speichern