Check the image's head validity when it is read

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Extract v1_read_bitmap() from v1_verify()

Also create read_bitmap_byte() to be reused with format 0002.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Extract generate_usedblocks_map() from v1_verify()

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Define v?_crc32() just under init_crc32_table()

This make possible to call v?_crc32() sooner in the code.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
squash with next commit
Implement v2_init() to read image 0002 description

Also include definition of stubs for the other v2 functions. They will be
implemented in the following commits.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Convert the blocks's usage map to a true bitmap format to use less RAM

In partclone's image format 0001, the blocks's usage map is recorded by
using 1 byte per block and libpartclone simple load those. This commit
convert the byte map into a bitmap when reading it. This reduce by ~87%
the amount of RAM used by imagemount.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
fixup! Convert the blocks's usage map to a true bitmap format to use less RAM
Implements v2_verify() and accompanying read_bitmap_bit()

The blocks's usage map in format 0002 is recorded as a bitmap and can be
absent when all the blocks are in use (like when the file system is not
supported).

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
fix previous commit
Format 0002 uses the same seek function than format 0001

Rename v1_seek() into v0_seek() to signify it is version neutral and keep
some uniformity in the dispatch table.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
rblock2offset() learns to handle blocks's offset based on the image's options

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Implements v2_readblock()

The checksum verification is only done when the blocks_per_checksum is
equal to 1, otherwize we would have to read many blocks to validate the
checksum of the block requested. That would greatly slowdown the performance.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Define pc_context_t in libpartclone.h to avoid duplication

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
partclone_imageinfo learns to handle images in format 0002

The format 0002 has a blocks_per_checksum option. This influence the
blocks count computation.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>