瀏覽代碼

[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 16 年之前
父節點
當前提交
a2686a55c4

+ 6
- 6
src/arch/i386/interface/pcbios/int13.c 查看文件

144
 static int int13_read_sectors ( struct int13_drive *drive,
144
 static int int13_read_sectors ( struct int13_drive *drive,
145
 				struct i386_all_regs *ix86 ) {
145
 				struct i386_all_regs *ix86 ) {
146
 	DBG ( "Read: " );
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
 static int int13_write_sectors ( struct int13_drive *drive,
163
 static int int13_write_sectors ( struct int13_drive *drive,
164
 				 struct i386_all_regs *ix86 ) {
164
 				 struct i386_all_regs *ix86 ) {
165
 	DBG ( "Write: " );
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
 static int int13_extended_read ( struct int13_drive *drive,
275
 static int int13_extended_read ( struct int13_drive *drive,
276
 				 struct i386_all_regs *ix86 ) {
276
 				 struct i386_all_regs *ix86 ) {
277
 	DBG ( "Extended read: " );
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
 static int int13_extended_write ( struct int13_drive *drive,
288
 static int int13_extended_write ( struct int13_drive *drive,
289
 				  struct i386_all_regs *ix86 ) {
289
 				  struct i386_all_regs *ix86 ) {
290
 	DBG ( "Extended write: " );
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
 	/* Scan through partition table and modify guesses for heads
488
 	/* Scan through partition table and modify guesses for heads
489
 	 * and sectors_per_track if we find any used partitions.
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
 		for ( i = 0 ; i < 4 ; i++ ) {
493
 		for ( i = 0 ; i < 4 ; i++ ) {
494
 			partition = &mbr.partitions[i];
494
 			partition = &mbr.partitions[i];
495
 			if ( ! partition->type )
495
 			if ( ! partition->type )

+ 6
- 2
src/drivers/block/ata.c 查看文件

139
 	return 0;
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
  * Initialise ATA device
148
  * Initialise ATA device
144
  *
149
  *
153
  */
158
  */
154
 int init_atadev ( struct ata_device *ata ) {
159
 int init_atadev ( struct ata_device *ata ) {
155
 	/** Fill in read and write methods, and get device capacity */
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
 	return ata_identify ( &ata->blockdev );
162
 	return ata_identify ( &ata->blockdev );
159
 }
163
 }

+ 6
- 2
src/drivers/block/ramdisk.c 查看文件

75
 	return 0;
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
 int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
83
 int init_ramdisk ( struct ramdisk *ramdisk, userptr_t data, size_t len,
79
 		   unsigned int blksize ) {
84
 		   unsigned int blksize ) {
80
 	
85
 	
82
 		blksize = 512;
87
 		blksize = 512;
83
 
88
 
84
 	ramdisk->data = data;
89
 	ramdisk->data = data;
85
-	ramdisk->blockdev.read = ramdisk_read;
86
-	ramdisk->blockdev.write = ramdisk_write;
90
+	ramdisk->blockdev.op = &ramdisk_operations;
87
 	ramdisk->blockdev.blksize = blksize;
91
 	ramdisk->blockdev.blksize = blksize;
88
 	ramdisk->blockdev.blocks = ( len / blksize );
92
 	ramdisk->blockdev.blocks = ( len / blksize );
89
 
93
 

+ 12
- 4
src/drivers/block/scsi.c 查看文件

228
 	return 0;
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
  * Initialise SCSI device
242
  * Initialise SCSI device
233
  *
243
  *
250
 	scsi_read_capacity_10 ( &scsi->blockdev );
260
 	scsi_read_capacity_10 ( &scsi->blockdev );
251
 
261
 
252
 	/* Try READ CAPACITY (10), which is a mandatory command, first. */
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
 	if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
264
 	if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
256
 		return rc;
265
 		return rc;
257
 
266
 
261
 	 * mandatory, so we can't just use it straight off.
270
 	 * mandatory, so we can't just use it straight off.
262
 	 */
271
 	 */
263
 	if ( scsi->blockdev.blocks == 0 ) {
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
 		if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
274
 		if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
267
 			return rc;
275
 			return rc;
268
 	}
276
 	}

+ 14
- 6
src/include/gpxe/blockdev.h 查看文件

10
 
10
 
11
 #include <gpxe/uaccess.h>
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
 	 * Read block
18
 	 * Read block
21
 	 *
19
 	 *
40
 			  unsigned long count, userptr_t buffer );
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
 #endif /* _GPXE_BLOCKDEV_H */
51
 #endif /* _GPXE_BLOCKDEV_H */

Loading…
取消
儲存