If the input file isn't a multiple of block_size, count the trailing
bit as a block in the output, otherwise bootloader will try to write
past the last declared block in the sparse file.
Test: Run sparse_test
Bug: 37339998
Change-Id: Iec143107d15795c6a6f4d3ea7b7515f6f16adcae
Switch vnsprintf to StringPrintf to avoid off-by-one, and switch
sparse_read.c to cpp.
Test: fastboot flash normal image with smaller sparse limit
Change-Id: Ia399b167625deb271bfd0ee3273071306d71c4d4
This now combines all the "libsparse" libraries into the same soong
target. A minor side-effect of this change is that the libsparse
static library depends on the libz shared library instead of the libz
static library. This minor change has no effect since targets using
the static libsparse library need to explicitly include either the
static libz or the shared one.
Bug: 34220783
Change-Id: I8f41586cf4c3336791cfa57ab4f5ae59a76d7ffa
CHUNK_HEADER structure type allows DATA chunk to be up to MAX_UINT
large.
The write() callback LEN parameter should be unsigned int.
Also:
- write() callback should continue to write data if less than expected
data have been written.
- gzerror() returns LEN on success, 0 otherwise
Test: manual
Change-Id: Id46d664b84c1a506f419524fe28055f784c2ae7a
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Adds CSV output option to output blocks to a CSV file.
Adds option to output SHA1 sum for each block.
Addressed misc lint errors
Test: compared output with previous version
Change-Id: I555c8816c6ef2b0b69dac2b9789fbfd8b2786a49
system/core/libsparse/sparse_read.c:260:51: warning: Dereference of null pointer (loaded from variable 'crc_ptr')
ret = process_crc32_chunk(fd, chunk_data_size, *crc_ptr);
system/core/libsparse/sparse_read.c:404:9: warning: Potential leak of memory pointed to by 'buf'
return 0;
Fixes leak in sparse_file_read_normal, and null pointer dereference
crash if an image with an obsolete CRC chunk was read with CRC checking
disabled.
Bug: 26904425
Change-Id: Ibc72cd37602929ae2c248bea1cdd1d22ea03baaf
make_ext4fs doesn't write out a CRC chunk, and append2simg doesn't
either, but append2simg was still performing a CRC on every input
block. Cuts append2simg time in half.
Change-Id: I678f807abbb741042461ed68a0f61b406d3665fb
The Clang/GCC formatting warning triggers for usage of %lld with off_t
on 64-bit because it's defined as a long int, not a long long int. It
isn't important, but it's technically undefined.
This fix is in anticipation of adding __attribute__((format(...))) to
many functions where it is currently missing.
Change-Id: I2bf33e6563a2892d2f54d7c582cbdeadf867e84f
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.
Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
This patch is used to fix two Bugs in backed_block.c
First, fix wrong comparing string way: we should use strcmp rather than
just compare their address. Second, fix using illegal memory risk in
bbl->last_used pointer. When entering queue_bb function,
bbl->last_used = new_bb, but in the following code if
queue_bb(xx, bb, new_bb) return ok, the space of new_bb is released. So
next time, if you use bbl->last_used pointer, may cause segment fault !
Change-Id: I6abb505f9b903b697448639fc64fb7518df5cca1
I caught the fastboot host command sending more data than the fastboot
device can accept. Fastboot host command was sending 36 surplus bytes
because of 3 skip chunks that were not taken into account in
move_chunks_up_to_len() algorithm.
Change-Id: I39a4a033c9b15893bd70e553f17116735ee4a48e
sparse_file_write_block calls functions that might failed. This patch
makes sparse_file_write_block catch the error code and propagate it.
Without this patch, fastboot crashes on a segmentation fault if
usb_write() fail during a sparse file image flashing.
Change-Id: If9c0e8dfac8fa380628a2504e13abe8cf7d62726
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
append2simg causes libsparse to write mmapped data from a file
back to that same file. On btrfs, this sometimes causes a page
of zeroes to be written instead of the file data. Work around
the issue by writing the output to a temporary file and then
renaming it over the original file.
Change-Id: Ia194b6ba0ddb8548747b63292b523756f544706a
This cleans up most of the size-related problems in system/core.
There are still a few changes needed for a clean 64-bit build,
but they look like they might require changes to things like the
fastboot protocol.
Change-Id: I1560425a289fa158e13e2e3173cc3e71976f92c0
Append2simg is a small utility designed to glue data to the end
of a sparse image. Beware that it doesn't do anything clever with
that data.
Change-Id: I33af330cb4f77e0842375797a35aebbb6af60163
Fix the issue that "out" pointer is dereferenced without checking.
Change-Id: I76a57ad7309841218231346f4807ef2be8628737
Signed-off-by: Hong-Mei Li <a21834@motorola.com>
last_block * s->block_size can overflow when writing large filesystems,
cast to 64 bits before multiplying.
Change-Id: I3e54097852ce7d0fd271eab53d65e666284898e4
Until ext4_utils switches to using libsparse, libext4_utils defines some
of the same symbols as libsparse. Fastboot links statically against
both of them, and there is no easy way to make the symbols hidden, so
just rename them in libsparse.
Change-Id: Idc2cfe20efe3c3a7fb8233f453a89bbbeb0dcc8b
Add sparse_file_len, which will compute the size of data that would
be produced if sparse_file_write was called. Useful combined with
sparse_file_callback.
Change-Id: I1a156d1071760f5559483954a5c62ffc20298703
Add sparse_file_repsarse, which splits chunks in an existing sparse
file such that the maximum size of a chunk, plus a header and footer,
is smaller than the given size. This will allow multiple smaller
sparse files to result in the same data as a large sparse file.
Change-Id: I177abdb958a23d5afd394ff265c5b0c6a3ff22fa
Add a new output file subclass that will call a callback for
each block as it is written. Will be used to measure the space
used by each sparse block to allow resparsing files.
Also add sparse_file_callback, which will write out a sparse
file by calling the provided write function.
Change-Id: I18707bd9c357b68da319cc07982e93d1c2b2bee2
Create two subclasses of output_file that can handle normal
and gzipped files, and refactor open_output_fd. Will allow
adding support for an output_file type that is not file
backed.
Change-Id: I26744c74d13f205cf17df1ea9caac1eea9c57357
Abstract the logic from simg2img into libsparse, and add logic
for reading a regular image into libsparse. simg2img then
becomes a simple wrapper around libsparse.
img2simg was not actually making the file sparse, it was using
sparse files to create multiple files that could be pieced back
together. Replace it with a simple wrapper around libsparse.
Its functionality will be replaced by an simg2simg that can
resparse a file into smaller chunks.
Change-Id: I266f70e1c750454183ce46c71a7bb66bbb033a26