qemu-img.c (3c9331c47f22224118d5019b0af8eac704824d8d) | qemu-img.c (67a0fd2a9bca204d2b39f910a97c7137636a0715) |
---|---|
1/* 2 * QEMU disk image utility 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 1058 unchanged lines hidden (view full) --- 1067 if (strict && total_sectors1 != total_sectors2) { 1068 ret = 1; 1069 qprintf(quiet, "Strict mode: Image size mismatch!\n"); 1070 goto out; 1071 } 1072 1073 for (;;) { 1074 int64_t status1, status2; | 1/* 2 * QEMU disk image utility 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 1058 unchanged lines hidden (view full) --- 1067 if (strict && total_sectors1 != total_sectors2) { 1068 ret = 1; 1069 qprintf(quiet, "Strict mode: Image size mismatch!\n"); 1070 goto out; 1071 } 1072 1073 for (;;) { 1074 int64_t status1, status2; |
1075 BlockDriverState *file; 1076 |
|
1075 nb_sectors = sectors_to_process(total_sectors, sector_num); 1076 if (nb_sectors <= 0) { 1077 break; 1078 } 1079 status1 = bdrv_get_block_status_above(bs1, NULL, sector_num, 1080 total_sectors1 - sector_num, | 1077 nb_sectors = sectors_to_process(total_sectors, sector_num); 1078 if (nb_sectors <= 0) { 1079 break; 1080 } 1081 status1 = bdrv_get_block_status_above(bs1, NULL, sector_num, 1082 total_sectors1 - sector_num, |
1081 &pnum1); | 1083 &pnum1, &file); |
1082 if (status1 < 0) { 1083 ret = 3; 1084 error_report("Sector allocation test failed for %s", filename1); 1085 goto out; 1086 } 1087 allocated1 = status1 & BDRV_BLOCK_ALLOCATED; 1088 1089 status2 = bdrv_get_block_status_above(bs2, NULL, sector_num, 1090 total_sectors2 - sector_num, | 1084 if (status1 < 0) { 1085 ret = 3; 1086 error_report("Sector allocation test failed for %s", filename1); 1087 goto out; 1088 } 1089 allocated1 = status1 & BDRV_BLOCK_ALLOCATED; 1090 1091 status2 = bdrv_get_block_status_above(bs2, NULL, sector_num, 1092 total_sectors2 - sector_num, |
1091 &pnum2); | 1093 &pnum2, &file); |
1092 if (status2 < 0) { 1093 ret = 3; 1094 error_report("Sector allocation test failed for %s", filename2); 1095 goto out; 1096 } 1097 allocated2 = status2 & BDRV_BLOCK_ALLOCATED; 1098 if (pnum1) { 1099 nb_sectors = MIN(nb_sectors, pnum1); --- 166 unchanged lines hidden (view full) --- 1266 int n; 1267 1268 convert_select_part(s, sector_num); 1269 1270 assert(s->total_sectors > sector_num); 1271 n = MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); 1272 1273 if (s->sector_next_status <= sector_num) { | 1094 if (status2 < 0) { 1095 ret = 3; 1096 error_report("Sector allocation test failed for %s", filename2); 1097 goto out; 1098 } 1099 allocated2 = status2 & BDRV_BLOCK_ALLOCATED; 1100 if (pnum1) { 1101 nb_sectors = MIN(nb_sectors, pnum1); --- 166 unchanged lines hidden (view full) --- 1268 int n; 1269 1270 convert_select_part(s, sector_num); 1271 1272 assert(s->total_sectors > sector_num); 1273 n = MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); 1274 1275 if (s->sector_next_status <= sector_num) { |
1276 BlockDriverState *file; |
|
1274 ret = bdrv_get_block_status(blk_bs(s->src[s->src_cur]), 1275 sector_num - s->src_cur_offset, | 1277 ret = bdrv_get_block_status(blk_bs(s->src[s->src_cur]), 1278 sector_num - s->src_cur_offset, |
1276 n, &n); | 1279 n, &n, &file); |
1277 if (ret < 0) { 1278 return ret; 1279 } 1280 1281 if (ret & BDRV_BLOCK_ZERO) { 1282 s->status = BLK_ZERO; 1283 } else if (ret & BDRV_BLOCK_DATA) { 1284 s->status = BLK_DATA; --- 911 unchanged lines hidden (view full) --- 2196 } 2197} 2198 2199static int get_block_status(BlockDriverState *bs, int64_t sector_num, 2200 int nb_sectors, MapEntry *e) 2201{ 2202 int64_t ret; 2203 int depth; | 1280 if (ret < 0) { 1281 return ret; 1282 } 1283 1284 if (ret & BDRV_BLOCK_ZERO) { 1285 s->status = BLK_ZERO; 1286 } else if (ret & BDRV_BLOCK_DATA) { 1287 s->status = BLK_DATA; --- 911 unchanged lines hidden (view full) --- 2199 } 2200} 2201 2202static int get_block_status(BlockDriverState *bs, int64_t sector_num, 2203 int nb_sectors, MapEntry *e) 2204{ 2205 int64_t ret; 2206 int depth; |
2207 BlockDriverState *file; |
|
2204 2205 /* As an optimization, we could cache the current range of unallocated 2206 * clusters in each file of the chain, and avoid querying the same 2207 * range repeatedly. 2208 */ 2209 2210 depth = 0; 2211 for (;;) { | 2208 2209 /* As an optimization, we could cache the current range of unallocated 2210 * clusters in each file of the chain, and avoid querying the same 2211 * range repeatedly. 2212 */ 2213 2214 depth = 0; 2215 for (;;) { |
2212 ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sectors); | 2216 ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &nb_sectors, 2217 &file); |
2213 if (ret < 0) { 2214 return ret; 2215 } 2216 assert(nb_sectors); 2217 if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { 2218 break; 2219 } 2220 bs = backing_bs(bs); --- 895 unchanged lines hidden --- | 2218 if (ret < 0) { 2219 return ret; 2220 } 2221 assert(nb_sectors); 2222 if (ret & (BDRV_BLOCK_ZERO|BDRV_BLOCK_DATA)) { 2223 break; 2224 } 2225 bs = backing_bs(bs); --- 895 unchanged lines hidden --- |