diff options
author | Ken Sumrall <ksumrall@android.com> | 2011-06-30 12:15:00 -0700 |
---|---|---|
committer | Ken Sumrall <ksumrall@android.com> | 2011-06-30 12:25:14 -0700 |
commit | dba332410528d11474ae9f878b6984755d55e299 (patch) | |
tree | 345be24b70d9e0f214415c36a31b0965d2b7bcc6 | |
parent | 107a9f161babc20daf915311146b0e864d3b4157 (diff) | |
download | extras-dba332410528d11474ae9f878b6984755d55e299.tar.gz |
Update simg2img to handle CHUNK_TYPE_FILL.
Change-Id: Ia4d178b535e1c154cf2b8e826ea1fba342b05658
-rw-r--r-- | ext4_utils/simg2img.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ext4_utils/simg2img.c b/ext4_utils/simg2img.c index a074b28e..228d289c 100644 --- a/ext4_utils/simg2img.c +++ b/ext4_utils/simg2img.c @@ -112,6 +112,36 @@ int process_raw_chunk(int in, int out, u32 blocks, u32 blk_sz, u32 *crc32) } +int process_fill_chunk(int in, int out, u32 blocks, u32 blk_sz, u32 *crc32) +{ + u64 len = (u64)blocks * blk_sz; + int ret; + int chunk; + u32 fill_val; + u32 *fillbuf; + unsigned int i; + + /* Fill copy_buf with the fill value */ + ret = read_all(in, &fill_val, sizeof(fill_val)); + fillbuf = (u32 *)copybuf; + for (i = 0; i < (COPY_BUF_SIZE / sizeof(fill_val)); i++) { + fillbuf[i] = fill_val; + } + + while (len) { + chunk = (len > COPY_BUF_SIZE) ? COPY_BUF_SIZE : len; + *crc32 = sparse_crc32(*crc32, copybuf, chunk); + ret = write_all(out, copybuf, chunk); + if (ret != chunk) { + fprintf(stderr, "write returned an error copying a raw chunk\n"); + exit(-1); + } + len -= chunk; + } + + return blocks; +} + int process_skip_chunk(int out, u32 blocks, u32 blk_sz, u32 *crc32) { /* len needs to be 64 bits, as the sparse file specifies the skip amount @@ -235,6 +265,14 @@ int main(int argc, char *argv[]) total_blocks += process_raw_chunk(in, out, chunk_header.chunk_sz, sparse_header.blk_sz, &crc32); break; + case CHUNK_TYPE_FILL: + if (chunk_header.total_sz != (sparse_header.chunk_hdr_sz + sizeof(u32)) ) { + fprintf(stderr, "Bogus chunk size for chunk %d, type Fill\n", i); + exit(-1); + } + total_blocks += process_fill_chunk(in, out, + chunk_header.chunk_sz, sparse_header.blk_sz, &crc32); + break; case CHUNK_TYPE_DONT_CARE: if (chunk_header.total_sz != sparse_header.chunk_hdr_sz) { fprintf(stderr, "Bogus chunk size for chunk %d, type Dont Care\n", i); |