From 087061b9cc1eba1965d6cd169183a10fc4165e85 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Thu, 23 Mar 2023 00:44:22 +0000 Subject: [PATCH] AOSP: 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 From AOSP commit: 7d0f5c1aca332da22e4878f5825e0ffb5122f96b --- contrib/android/ext2simg.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/contrib/android/ext2simg.c b/contrib/android/ext2simg.c index 9b594f3..811c60d 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) -- 1.8.3.1