Revision 6c6ea921 block/vpc.c

b/block/vpc.c
371 371
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
372 372
                    uint8_t *buf, int nb_sectors)
373 373
{
374
    BDRVVPCState *s = bs->opaque;
374 375
    int ret;
375 376
    int64_t offset;
377
    int64_t sectors, sectors_per_block;
376 378

  
377 379
    while (nb_sectors > 0) {
378 380
        offset = get_sector_offset(bs, sector_num, 0);
379 381

  
382
        sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;
383
        sectors = sectors_per_block - (sector_num % sectors_per_block);
384
        if (sectors > nb_sectors) {
385
            sectors = nb_sectors;
386
        }
387

  
380 388
        if (offset == -1) {
381
            memset(buf, 0, 512);
389
            memset(buf, 0, sectors * BDRV_SECTOR_SIZE);
382 390
        } else {
383
            ret = bdrv_pread(bs->file, offset, buf, 512);
384
            if (ret != 512)
391
            ret = bdrv_pread(bs->file, offset, buf,
392
                sectors * BDRV_SECTOR_SIZE);
393
            if (ret != sectors * BDRV_SECTOR_SIZE) {
385 394
                return -1;
395
            }
386 396
        }
387 397

  
388
        nb_sectors--;
389
        sector_num++;
390
        buf += 512;
398
        nb_sectors -= sectors;
399
        sector_num += sectors;
400
        buf += sectors * BDRV_SECTOR_SIZE;
391 401
    }
392 402
    return 0;
393 403
}
......
395 405
static int vpc_write(BlockDriverState *bs, int64_t sector_num,
396 406
    const uint8_t *buf, int nb_sectors)
397 407
{
408
    BDRVVPCState *s = bs->opaque;
398 409
    int64_t offset;
410
    int64_t sectors, sectors_per_block;
399 411
    int ret;
400 412

  
401 413
    while (nb_sectors > 0) {
402 414
        offset = get_sector_offset(bs, sector_num, 1);
403 415

  
416
        sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;
417
        sectors = sectors_per_block - (sector_num % sectors_per_block);
418
        if (sectors > nb_sectors) {
419
            sectors = nb_sectors;
420
        }
421

  
404 422
        if (offset == -1) {
405 423
            offset = alloc_block(bs, sector_num);
406 424
            if (offset < 0)
407 425
                return -1;
408 426
        }
409 427

  
410
        ret = bdrv_pwrite(bs->file, offset, buf, 512);
411
        if (ret != 512)
428
        ret = bdrv_pwrite(bs->file, offset, buf, sectors * BDRV_SECTOR_SIZE);
429
        if (ret != sectors * BDRV_SECTOR_SIZE) {
412 430
            return -1;
431
        }
413 432

  
414
        nb_sectors--;
415
        sector_num++;
416
        buf += 512;
433
        nb_sectors -= sectors;
434
        sector_num += sectors;
435
        buf += sectors * BDRV_SECTOR_SIZE;
417 436
    }
418 437

  
419 438
    return 0;

Also available in: Unified diff