aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-03-23 00:44:22 +0000
committerEric Biggers <ebiggers@google.com>2023-03-23 00:44:22 +0000
commit7d0f5c1aca332da22e4878f5825e0ffb5122f96b (patch)
treebb89ccde1d437e7ab2d65f596929025351945010
parentc88ea796fbf7f4c79155196ec483681b3733bbff (diff)
downloade2fsprogs-7d0f5c1aca332da22e4878f5825e0ffb5122f96b.tar.gz
ext2simg: clean up add_chunk()
Remove a level of indentation, check a bool in the normal way, and simplify the linked list handling. No change in behavior. Change-Id: I12589a254f155b1c40418458a666b87c7ef5c1cf Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r--contrib/android/ext2simg.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/contrib/android/ext2simg.c b/contrib/android/ext2simg.c
index 9b594f37..811c60d6 100644
--- a/contrib/android/ext2simg.c
+++ b/contrib/android/ext2simg.c
@@ -68,33 +68,27 @@ static struct buf_item {
static void add_chunk(ext2_filsys fs, struct sparse_file *s,
blk_t chunk_start, int num_blks)
{
- int retval;
uint64_t len = (uint64_t)num_blks * fs->blocksize;
int64_t offset = (int64_t)chunk_start * fs->blocksize;
+ struct buf_item *bi;
+ int retval;
- if (params.overwrite_input == false) {
+ if (!params.overwrite_input) {
if (sparse_file_add_file(s, params.in_file, offset, len, chunk_start) < 0)
sparse_fatal("adding data to the sparse file");
- } else {
- /*
- * The input file will be overwritten, make a copy of
- * the blocks
- */
- struct buf_item *bi = calloc(1, sizeof(struct buf_item) + len);
- if (buf_list == NULL)
- buf_list = bi;
- else {
- bi->next = buf_list;
- buf_list = bi;
- }
+ return;
+ }
- retval = io_channel_read_blk64(fs->io, chunk_start, num_blks, bi->buf);
- if (retval < 0)
- ext2fs_fatal(retval, "reading data from %s", params.in_file);
+ /* The input file will be overwritten, so make a copy of the blocks. */
+ bi = calloc(1, sizeof(*bi) + len);
+ bi->next = buf_list;
+ buf_list = bi;
+ retval = io_channel_read_blk64(fs->io, chunk_start, num_blks, bi->buf);
+ if (retval < 0)
+ ext2fs_fatal(retval, "reading data from %s", params.in_file);
- if (sparse_file_add_data(s, bi->buf, len, chunk_start) < 0)
- sparse_fatal("adding data to the sparse file");
- }
+ if (sparse_file_add_data(s, bi->buf, len, chunk_start) < 0)
+ sparse_fatal("adding data to the sparse file");
}
static void free_chunks(void)