mirror of https://github.com/xemu-project/xemu.git
qemu-io: Switch 'alloc' command to byte-based length
For the 'alloc' command, accepting an offset in bytes but a length in sectors, and reporting output in sectors, is confusing. Do everything in bytes, and adjust the expected output accordingly. Signed-off-by: Eric Blake <eblake@redhat.com> Message-id: 20170429191419.30051-3-eblake@redhat.com Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
1bce6b4ce3
commit
4401fdc77c
|
@ -1760,7 +1760,7 @@ out:
|
||||||
static int alloc_f(BlockBackend *blk, int argc, char **argv)
|
static int alloc_f(BlockBackend *blk, int argc, char **argv)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs = blk_bs(blk);
|
BlockDriverState *bs = blk_bs(blk);
|
||||||
int64_t offset, sector_num, nb_sectors, remaining;
|
int64_t offset, sector_num, nb_sectors, remaining, count;
|
||||||
char s1[64];
|
char s1[64];
|
||||||
int num, ret;
|
int num, ret;
|
||||||
int64_t sum_alloc;
|
int64_t sum_alloc;
|
||||||
|
@ -1776,18 +1776,24 @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
nb_sectors = cvtnum(argv[2]);
|
count = cvtnum(argv[2]);
|
||||||
if (nb_sectors < 0) {
|
if (count < 0) {
|
||||||
print_cvtnum_err(nb_sectors, argv[2]);
|
print_cvtnum_err(count, argv[2]);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (nb_sectors > INT_MAX) {
|
} else if (count > INT_MAX * BDRV_SECTOR_SIZE) {
|
||||||
printf("length argument cannot exceed %d, given %s\n",
|
printf("length argument cannot exceed %llu, given %s\n",
|
||||||
INT_MAX, argv[2]);
|
INT_MAX * BDRV_SECTOR_SIZE, argv[2]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nb_sectors = 1;
|
count = BDRV_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
|
if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
|
||||||
|
printf("%" PRId64 " is not a sector-aligned value for 'count'\n",
|
||||||
|
count);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
nb_sectors = count >> BDRV_SECTOR_BITS;
|
||||||
|
|
||||||
remaining = nb_sectors;
|
remaining = nb_sectors;
|
||||||
sum_alloc = 0;
|
sum_alloc = 0;
|
||||||
|
@ -1811,8 +1817,8 @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
|
||||||
|
|
||||||
cvtstr(offset, s1, sizeof(s1));
|
cvtstr(offset, s1, sizeof(s1));
|
||||||
|
|
||||||
printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n",
|
printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n",
|
||||||
sum_alloc, nb_sectors, s1);
|
sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, s1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1822,8 +1828,8 @@ static const cmdinfo_t alloc_cmd = {
|
||||||
.argmin = 1,
|
.argmin = 1,
|
||||||
.argmax = 2,
|
.argmax = 2,
|
||||||
.cfunc = alloc_f,
|
.cfunc = alloc_f,
|
||||||
.args = "off [sectors]",
|
.args = "offset [count]",
|
||||||
.oneline = "checks if a sector is present in the file",
|
.oneline = "checks if offset is allocated in the file",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -542,8 +542,8 @@ Testing conversion with -B TEST_DIR/t.IMGFMT.base
|
||||||
|
|
||||||
Checking if backing clusters are allocated when they shouldn't
|
Checking if backing clusters are allocated when they shouldn't
|
||||||
|
|
||||||
0/128 sectors allocated at offset 1 MiB
|
0/65536 bytes allocated at offset 1 MiB
|
||||||
0/128 sectors allocated at offset 4.001 GiB
|
0/65536 bytes allocated at offset 4.001 GiB
|
||||||
Reading
|
Reading
|
||||||
|
|
||||||
=== IO: pattern 42
|
=== IO: pattern 42
|
||||||
|
@ -1086,8 +1086,8 @@ Testing conversion with -o backing_file=TEST_DIR/t.IMGFMT.base
|
||||||
|
|
||||||
Checking if backing clusters are allocated when they shouldn't
|
Checking if backing clusters are allocated when they shouldn't
|
||||||
|
|
||||||
0/128 sectors allocated at offset 1 MiB
|
0/65536 bytes allocated at offset 1 MiB
|
||||||
0/128 sectors allocated at offset 4.001 GiB
|
0/65536 bytes allocated at offset 4.001 GiB
|
||||||
Reading
|
Reading
|
||||||
|
|
||||||
=== IO: pattern 42
|
=== IO: pattern 42
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
function do_is_allocated() {
|
function do_is_allocated() {
|
||||||
local start=$1
|
local start=$1
|
||||||
local size=$(( $2 / 512))
|
local size=$2
|
||||||
local step=$3
|
local step=$3
|
||||||
local count=$4
|
local count=$4
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue