提交 bd6b4646 编写于 作者: C Cole Robinson

storagefile: Push 'start' into qcow2GetBackingStoreFormat

This is a step towards making this qcow2GetBackingStoreFormat into
a generic qcow2 extensions parser
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NCole Robinson <crobinso@redhat.com>
上级 242e7ac5
......@@ -430,10 +430,22 @@ static int
qcow2GetBackingStoreFormat(int *format,
const char *buf,
size_t buf_size,
size_t extension_start,
size_t extension_end)
{
size_t offset = extension_start;
size_t offset;
size_t extension_start;
int version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
if (version < 2) {
/* QCow1 doesn't have the extensions capability
* used to store backing format */
return 0;
}
if (version == 2)
extension_start = QCOW2_HDR_TOTAL_SIZE;
else
extension_start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE);
/*
* The extensions take format of
......@@ -445,6 +457,7 @@ qcow2GetBackingStoreFormat(int *format,
* Unknown extensions can be ignored by skipping
* over "length" bytes in the data stream.
*/
offset = extension_start;
while (offset < (buf_size-8) &&
offset < (extension_end-8)) {
unsigned int magic = virReadBufInt32BE(buf + offset);
......@@ -487,8 +500,6 @@ qcowXGetBackingStore(char **res,
{
unsigned long long offset;
unsigned int size;
unsigned long long start;
int version;
*res = NULL;
*format = VIR_STORAGE_FILE_AUTO;
......@@ -546,18 +557,8 @@ qcowXGetBackingStore(char **res,
* is stored at QCOW2v3_HDR_SIZE
*/
version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
if (version >= 2) {
/* QCow1 doesn't have the extensions capability
* used to store backing format */
if (version == 2)
start = QCOW2_HDR_TOTAL_SIZE;
else
start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE);
if (qcow2GetBackingStoreFormat(format, buf, buf_size,
start, offset) < 0)
return BACKING_STORE_INVALID;
}
if (qcow2GetBackingStoreFormat(format, buf, buf_size, offset) < 0)
return BACKING_STORE_INVALID;
return BACKING_STORE_OK;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册