nbd: Switch to byte-based block access
Sector-based blk_read() should die; switch to byte-based blk_pread() instead. Add a constant for our magic number 512, to make it obvious that this size will NOT change even if BDRV_SECTOR_SIZE does, even though the two happen to be the same for now. Split assignments from conditionals to keep checkpatch.pl happy. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
		
							parent
							
								
									26a122d3d4
								
							
						
					
					
						commit
						bd31c214c3
					
				
							
								
								
									
										13
									
								
								qemu-nbd.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								qemu-nbd.c
									
									
									
									
									
								
							@ -46,6 +46,8 @@
 | 
				
			|||||||
#define QEMU_NBD_OPT_TLSCREDS      261
 | 
					#define QEMU_NBD_OPT_TLSCREDS      261
 | 
				
			||||||
#define QEMU_NBD_OPT_IMAGE_OPTS    262
 | 
					#define QEMU_NBD_OPT_IMAGE_OPTS    262
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MBR_SIZE 512
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static NBDExport *exp;
 | 
					static NBDExport *exp;
 | 
				
			||||||
static bool newproto;
 | 
					static bool newproto;
 | 
				
			||||||
static int verbose;
 | 
					static int verbose;
 | 
				
			||||||
@ -159,12 +161,13 @@ static int find_partition(BlockBackend *blk, int partition,
 | 
				
			|||||||
                          off_t *offset, off_t *size)
 | 
					                          off_t *offset, off_t *size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct partition_record mbr[4];
 | 
					    struct partition_record mbr[4];
 | 
				
			||||||
    uint8_t data[512];
 | 
					    uint8_t data[MBR_SIZE];
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    int ext_partnum = 4;
 | 
					    int ext_partnum = 4;
 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((ret = blk_read(blk, 0, data, 1)) < 0) {
 | 
					    ret = blk_pread(blk, 0, data, sizeof(data));
 | 
				
			||||||
 | 
					    if (ret < 0) {
 | 
				
			||||||
        error_report("error while reading: %s", strerror(-ret));
 | 
					        error_report("error while reading: %s", strerror(-ret));
 | 
				
			||||||
        exit(EXIT_FAILURE);
 | 
					        exit(EXIT_FAILURE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -182,10 +185,12 @@ static int find_partition(BlockBackend *blk, int partition,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (mbr[i].system == 0xF || mbr[i].system == 0x5) {
 | 
					        if (mbr[i].system == 0xF || mbr[i].system == 0x5) {
 | 
				
			||||||
            struct partition_record ext[4];
 | 
					            struct partition_record ext[4];
 | 
				
			||||||
            uint8_t data1[512];
 | 
					            uint8_t data1[MBR_SIZE];
 | 
				
			||||||
            int j;
 | 
					            int j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) < 0) {
 | 
					            ret = blk_pread(blk, mbr[i].start_sector_abs * MBR_SIZE,
 | 
				
			||||||
 | 
					                            data1, sizeof(data1));
 | 
				
			||||||
 | 
					            if (ret < 0) {
 | 
				
			||||||
                error_report("error while reading: %s", strerror(-ret));
 | 
					                error_report("error while reading: %s", strerror(-ret));
 | 
				
			||||||
                exit(EXIT_FAILURE);
 | 
					                exit(EXIT_FAILURE);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user