Am 09.12.2011 08:58, schrieb Li Zhi Hui: > v2: modify some errors > > Signed-off-by: Li Zhi Hui <zhihu...@linux.vnet.ibm.com> > --- > block/cow.c | 31 ++++++++++++++++++------------- > 1 files changed, 18 insertions(+), 13 deletions(-) > > diff --git a/block/cow.c b/block/cow.c > index 3c52735..51ca681 100644 > --- a/block/cow.c > +++ b/block/cow.c > @@ -64,15 +64,17 @@ static int cow_open(BlockDriverState *bs, int flags) > struct cow_header_v2 cow_header; > int bitmap_size; > int64_t size; > + int ret; > > /* see if it is a cow image */ > - if (bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)) != > - sizeof(cow_header)) { > + ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)); > + if (ret < 0) { > goto fail; > } > > if (be32_to_cpu(cow_header.magic) != COW_MAGIC || > be32_to_cpu(cow_header.version) != COW_VERSION) { > + ret = -1;
ret is interpreted as -errno by the caller, so usually on Linux systems you'll get a -EPERM (Operation not permitted) error message, which doesn't describe the error very well. I think a better return value for a wrong magic would be -EINVAL. For a wrong version have a look at the qcow2 code (qerror_report and -ENOTSUP). Kevin