qcow2: Clarify that compressed cluster offset requires shift
PATCH 1/1 qcow2: Clarify that compressed cluster offset requires shift
The specs for the host cluster offset of a compressed cluster were not clear that the offset is in terms of sectors, and requires a shift by 9 to be a byte offset. Add some more text to make the interpretation obvious.
--- docs/specs/qcow2.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
docs/specs/qcow2.txt +7 -2
@@ -323,11 +323,16 @@ Standard Cluster Descriptor: Compressed Clusters Descriptor (x = 62 - (cluster_bits - 8)): - Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x: Bits 9-(x+9) of host cluster offset. This is + usually _not_ aligned to a cluster boundary! x+1 - 61: Compressed size of the images in sectors of 512 bytes +The bits of the host cluster offset not specified in the cluster descriptor +are 0 (bits 0-8 are obvious because a 512-byte sector is the smallest +addressable unit, while bits 56-63 implies that a qcow2 file cannot exceed +2^56 bytes in size). + If a cluster is unallocated, read requests shall read the data from the backing file (except if bit 0 in the Standard Cluster Descriptor is set). If there is no backing file or the backing file is smaller than the image, they shall read
Signature · 1 line
2.5.0
Quoted 16 lines · Eric Blake
The specs for the host cluster offset of a compressed cluster were not clear that the offset is in terms of sectors, and requires a shift by 9 to be a byte offset. Add some more text to make the interpretation obvious.
Signed-off-by Eric Blake <[email protected]>--- docs/specs/qcow2.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)docs/specs/qcow2.txt +0
-0
docs/specs/qcow2.txt Standard Cluster Descriptor: · line 326
Quoted 6 lines
docs/specs/qcow2.txt +1
-2@@ -323,11 +323,16 @@ Standard Cluster Descriptor: Compressed Clusters Descriptor (x = 62 - (cluster_bits - 8)): - Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x: Bits 9-(x+9) of host cluster offset. This is
I'd rather use one of "9..(x+9)", "[9, x+9]", "9 - (x+9)", "9—(x+9)" in order to clarify that this is not a minus but a range.
Max
Quoted 13 lines
docs/specs/qcow2.txt +6
-0+ usually _not_ aligned to a cluster boundary! x+1 - 61: Compressed size of the images in sectors of 512 bytes +The bits of the host cluster offset not specified in the cluster descriptor +are 0 (bits 0-8 are obvious because a 512-byte sector is the smallest +addressable unit, while bits 56-63 implies that a qcow2 file cannot exceed +2^56 bytes in size). + If a cluster is unallocated, read requests shall read the data from the backing file (except if bit 0 in the Standard Cluster Descriptor is set). If there is no backing file or the backing file is smaller than the image, they shall read
Quoted 18 lines · Max Reitz
Quoted 17 lines · Eric Blake
The specs for the host cluster offset of a compressed cluster were not clear that the offset is in terms of sectors, and requires a shift by 9 to be a byte offset. Add some more text to make the interpretation obvious.
Signed-off-by Eric Blake <[email protected]>--- docs/specs/qcow2.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)docs/specs/qcow2.txt +0
-0@@ -323,11 +323,16 @@ Standard Cluster Descriptor:
Quoted 8 lines
docs/specs/qcow2.txt Standard Cluster Descriptor: · line 326
Quoted 5 lines
docs/specs/qcow2.txt +1
-2Compressed Clusters Descriptor (x = 62 - (cluster_bits - 8)): - Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x: Bits 9-(x+9) of host cluster offset. This isI'd rather use one of "9..(x+9)", "[9, x+9]", "9 - (x+9)", "9—(x+9)" in order to clarify that this is not a minus but a range.
...unless, of course, this is actually a byte offset, which it seems to be, judging from qcow2_get_cluster_offset() (and qcow2_decompress_cluster(), as Kevin said on IRC).
Max
Quoted 6 lines · Max Reitz
Quoted 6 lines
Quoted 5 lines
Compressed Clusters Descriptor (x = 62 - (
cluster_bits- 8)):docs/specs/qcow2.txt +1
-2- Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x: Bits 9-(x+9) of host cluster offset. This is
Quoted 6 lines
Quoted 2 lines
I'd rather use one of "9..(x+9)", "[9, x+9]", "9 - (x+9)", "9—(x+9)" in order to clarify that this is not a minus but a range.
...unless, of course, this is actually a byte offset, which it seems to be, judging from
qcow2_get_cluster_offset()(andqcow2_decompress_cluster(), as Kevin said on IRC).
Hmm, then I may be totally wrong. (Serves me right for trying to write a spec patch without testing actual behavior).
At the least, we may want to say that things are usually not aligned to even a _sector_ boundary (not just cluster boundary), and also clarify whether the sector length is truncated or rounded up (zlib doesn't care about trailing garbage during decompression, but you DO need to know how many sectors to read to ensure that you are supplying zlib with trailing garbage, rather than a truncated stream).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 18 lines · Eric Blake
Quoted 6 lines · Max Reitz
Quoted 6 lines
Quoted 5 lines
Compressed Clusters Descriptor (x = 62 - (
cluster_bits- 8)):docs/specs/qcow2.txt +1
-2- Bit 0 - x: Host cluster offset. This is usually _not_ aligned to a - cluster boundary! + Bit 0 - x: Bits 9-(x+9) of host cluster offset. This isQuoted 6 lines
Quoted 2 lines
I'd rather use one of "9..(x+9)", "[9, x+9]", "9 - (x+9)", "9—(x+9)" in order to clarify that this is not a minus but a range.
...unless, of course, this is actually a byte offset, which it seems to be, judging from
qcow2_get_cluster_offset()(andqcow2_decompress_cluster(), as Kevin said on IRC).Hmm, then I may be totally wrong. (Serves me right for trying to write a spec patch without testing actual behavior).
Quoted 6 lines
At the least, we may want to say that things are usually not aligned to even a _sector_ boundary (not just cluster boundary), and also clarify whether the sector length is truncated or rounded up (zlib doesn't care about trailing garbage during decompression, but you DO need to know how many sectors to read to ensure that you are supplying zlib with trailing garbage, rather than a truncated stream).
Yes, I agree.
Max