Revision 9a8c4cce

b/block.c
717 717
    uint8_t tmp_buf[BDRV_SECTOR_SIZE];
718 718
    int len, nb_sectors, count;
719 719
    int64_t sector_num;
720
    int ret;
720 721

  
721 722
    count = count1;
722 723
    /* first read to align to sector start */
......
725 726
        len = count;
726 727
    sector_num = offset >> BDRV_SECTOR_BITS;
727 728
    if (len > 0) {
728
        if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
729
            return -EIO;
729
        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
730
            return ret;
730 731
        memcpy(buf, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), len);
731 732
        count -= len;
732 733
        if (count == 0)
......
738 739
    /* read the sectors "in place" */
739 740
    nb_sectors = count >> BDRV_SECTOR_BITS;
740 741
    if (nb_sectors > 0) {
741
        if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0)
742
            return -EIO;
742
        if ((ret = bdrv_read(bs, sector_num, buf, nb_sectors)) < 0)
743
            return ret;
743 744
        sector_num += nb_sectors;
744 745
        len = nb_sectors << BDRV_SECTOR_BITS;
745 746
        buf += len;
......
748 749

  
749 750
    /* add data from the last sector */
750 751
    if (count > 0) {
751
        if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
752
            return -EIO;
752
        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
753
            return ret;
753 754
        memcpy(buf, tmp_buf, count);
754 755
    }
755 756
    return count1;
......
761 762
    uint8_t tmp_buf[BDRV_SECTOR_SIZE];
762 763
    int len, nb_sectors, count;
763 764
    int64_t sector_num;
765
    int ret;
764 766

  
765 767
    count = count1;
766 768
    /* first write to align to sector start */
......
769 771
        len = count;
770 772
    sector_num = offset >> BDRV_SECTOR_BITS;
771 773
    if (len > 0) {
772
        if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
773
            return -EIO;
774
        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
775
            return ret;
774 776
        memcpy(tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), buf, len);
775
        if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
776
            return -EIO;
777
        if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
778
            return ret;
777 779
        count -= len;
778 780
        if (count == 0)
779 781
            return count1;
......
784 786
    /* write the sectors "in place" */
785 787
    nb_sectors = count >> BDRV_SECTOR_BITS;
786 788
    if (nb_sectors > 0) {
787
        if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0)
788
            return -EIO;
789
        if ((ret = bdrv_write(bs, sector_num, buf, nb_sectors)) < 0)
790
            return ret;
789 791
        sector_num += nb_sectors;
790 792
        len = nb_sectors << BDRV_SECTOR_BITS;
791 793
        buf += len;
......
794 796

  
795 797
    /* add data from the last sector */
796 798
    if (count > 0) {
797
        if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
798
            return -EIO;
799
        if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
800
            return ret;
799 801
        memcpy(tmp_buf, buf, count);
800
        if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
801
            return -EIO;
802
        if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
803
            return ret;
802 804
    }
803 805
    return count1;
804 806
}

Also available in: Unified diff