提交 16fffd82 编写于 作者: C Cole Robinson

storagefile: Push extension_end calc to 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>
上级 bd6b4646
...@@ -429,11 +429,11 @@ cowGetBackingStore(char **res, ...@@ -429,11 +429,11 @@ cowGetBackingStore(char **res,
static int static int
qcow2GetBackingStoreFormat(int *format, qcow2GetBackingStoreFormat(int *format,
const char *buf, const char *buf,
size_t buf_size, size_t buf_size)
size_t extension_end)
{ {
size_t offset; size_t offset;
size_t extension_start; size_t extension_start;
size_t extension_end;
int version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION); int version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
if (version < 2) { if (version < 2) {
...@@ -447,6 +447,37 @@ qcow2GetBackingStoreFormat(int *format, ...@@ -447,6 +447,37 @@ qcow2GetBackingStoreFormat(int *format,
else else
extension_start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE); extension_start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE);
/*
* Traditionally QCow2 files had a layout of
*
* [header]
* [backingStoreName]
*
* Although the backingStoreName typically followed
* the header immediately, this was not required by
* the format. By specifying a higher byte offset for
* the backing file offset in the header, it was
* possible to leave space between the header and
* start of backingStore.
*
* This hack is now used to store extensions to the
* qcow2 format:
*
* [header]
* [extensions]
* [backingStoreName]
*
* Thus the file region to search for extensions is
* between the end of the header (QCOW2_HDR_TOTAL_SIZE)
* and the start of the backingStoreName (offset)
*
* for qcow2 v3 images, the length of the header
* is stored at QCOW2v3_HDR_SIZE
*/
extension_end = virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSET);
if (extension_end > buf_size)
return -1;
/* /*
* The extensions take format of * The extensions take format of
* *
...@@ -506,6 +537,7 @@ qcowXGetBackingStore(char **res, ...@@ -506,6 +537,7 @@ qcowXGetBackingStore(char **res,
if (buf_size < QCOWX_HDR_BACKING_FILE_OFFSET+8+4) if (buf_size < QCOWX_HDR_BACKING_FILE_OFFSET+8+4)
return BACKING_STORE_INVALID; return BACKING_STORE_INVALID;
offset = virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSET); offset = virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSET);
if (offset > buf_size) if (offset > buf_size)
return BACKING_STORE_INVALID; return BACKING_STORE_INVALID;
...@@ -529,35 +561,7 @@ qcowXGetBackingStore(char **res, ...@@ -529,35 +561,7 @@ qcowXGetBackingStore(char **res,
memcpy(*res, buf + offset, size); memcpy(*res, buf + offset, size);
(*res)[size] = '\0'; (*res)[size] = '\0';
/* if (qcow2GetBackingStoreFormat(format, buf, buf_size) < 0)
* Traditionally QCow2 files had a layout of
*
* [header]
* [backingStoreName]
*
* Although the backingStoreName typically followed
* the header immediately, this was not required by
* the format. By specifying a higher byte offset for
* the backing file offset in the header, it was
* possible to leave space between the header and
* start of backingStore.
*
* This hack is now used to store extensions to the
* qcow2 format:
*
* [header]
* [extensions]
* [backingStoreName]
*
* Thus the file region to search for extensions is
* between the end of the header (QCOW2_HDR_TOTAL_SIZE)
* and the start of the backingStoreName (offset)
*
* for qcow2 v3 images, the length of the header
* is stored at QCOW2v3_HDR_SIZE
*/
if (qcow2GetBackingStoreFormat(format, buf, buf_size, offset) < 0)
return BACKING_STORE_INVALID; return BACKING_STORE_INVALID;
return BACKING_STORE_OK; return BACKING_STORE_OK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册