toolbox: do not rewrite version.h if the version is the same

When version.h is modified, every programs are recompiled. By avoiding to
modify it, we avoid to recompile every thing at each execution of make.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Use the right type spec when calling log_mesg()
Fix warnings from btrfs by using the same type than them

btrfs uses u64 instead of uint64_t and they force the compiler to check
the types passed to the API.
Add functions to allocate and initialize the bitmap

This make the code a little bit easier to read and maintain.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Declare read_bitmap() and initial_image_hdr() in one place

This reduce code duplication and simplify the modification of their
declaration when they must be updated.

readbitmap() is renamed read_bitmap() to follow the coding standard.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Declare fs_opt from fs_common.h instead of declaring it in every fs' implementation

This is simply to reduce code deduplication.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Disable struct's members alignment and regroup the structs' definitions

The compiler automatically align the struct's members on the platform's
memory boundary. This is to prevent a lost of performance when the members
cross the memory boundary of the platform. If the alignment is not disabled,
the image created with a 64 bits version is not usable by a 32 bits version
and vice-versa.

In our case, a padding of 2 bytes is added before block_size to align it
on the next address divisible by 4.

    00000000  70 61 72 74 63 6c 6f 6e  65 2d 69 6d 61 67 65 45  |partclone-imageE|
    00000010  58 54 46 53 00 00 00 00  00 00 00 00 00 00 30 30  |XTFS..........00|
    00000020  30 31 XX XX 00-04-00-00  00-d0-ff-1f-00-00-00-00  |01..............|
    00000030  f4-ff-07-00-00-00-00-00  be-c3-01-00-00-00-00-00  |................|
    00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Move image_head writing in write_image_head

This change will make the modifications for image version 0002 more
localized.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Move bitmap writing in write_image_bitmap()

This change will simplify the implementation of image 0002, in which
the user can choose the bitmap format to be recorded.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Move bitmap's signature check in get_image_bitmap()

This change simplify the implementation of image version 0002,
in which we have to read both version.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Teach restore_image_hdr() to validate the header he gets from the image

This change is to simplify the handling of various image version.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Remove repetition in Makefile.in

Use a variable instead of repeating the same files all over.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Prepare the code to handle a new image version

Also rename VERSION_SIZE into IMAGE_VERSION_SIZE to make it more uniform.

IMAGE_VERSION_CURRENT is to be used when the code does not care for other
versions and can only handle the current image version.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Move the file system's information into its own struct

This commit impacts a lot of code, but it is mostly the remplacement of the
type image_head by file_system_info. The code uses file_system_info_v2
instead of *_v1 because the field "fs" is not available otherwise.
image_head is only required inside load_image_desc() and write_image_desc().

The functions get_image_* are renamed into load_image_* to indicate they
load the informations from an image file.

initial_image_hdr() is renamed into read_super_blocks() to indicate more
precisely that it read the super blocks from a device.

The image format written by partclone is still 0001.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Introduce image_options and supports a dynamic checksum's size

A lot of changes in preparation for the image format 0002. All the changes
require the image_options to determine how to handle the image:
- what is the size of the checksum?

check_mem_size() is rewritten to handle the various cases.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Handle the checksum in a generic way

Image version 0002 must supports various checksum algorithms. To that end,
we move the checksum code in a new file and we define generic functions to
hide the details of the selected algorithm.

After this, partclone still generates images in version 0001, but the bases
to supports more checksum algorithms is in place.

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
write_image_bitmap() learns to write various type of bitmap

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
load_image_bitmap() learns to load various type of bitmap
Clone & Restore operations learns to handle checksum on a block count other than 1

These changes update the code producing the checksum and make it aware of
value for blocks_per_checksum other than 1.

BUG: fail to validate the latest checksum

Signed-off-by: Patryck Rouleau <pfrouleau@gmail.com>
Partclone learns to handle various image version

This commit updates load_image_desc() to handle the image by determining its
version. The version written is still 0001.

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