f2fs-tools: add the max chunk size limit in sparse image
authorGao Ming <gaoming20@huawei.com>
Mon, 15 Oct 2018 13:24:57 +0000 (21:24 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 21 Nov 2018 19:38:23 +0000 (11:38 -0800)
Malloc Failure occurs in 32bit Windows, when using fastboot.exe flash the
 f2fs sparse image filling with  up to 2G chunk size.

Signed-off-by: Gao Ming <gaoming20@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
lib/libf2fs_io.c

index 76d283d..47917ab 100644 (file)
@@ -311,6 +311,7 @@ int f2fs_init_sparse_file(void)
 #endif
 }
 
+#define MAX_CHUNK_SIZE (1 * 1024 * 1024 * 1024ULL)
 int f2fs_finalize_device(void)
 {
        int i;
@@ -337,6 +338,12 @@ int f2fs_finalize_device(void)
                                chunk_start = -1;
                        } else if (blocks[j] && chunk_start == -1) {
                                chunk_start = j;
+                       } else if (blocks[j] && (chunk_start != -1) &&
+                                (j + 1 - chunk_start >=
+                                       (MAX_CHUNK_SIZE / F2FS_BLKSIZE))) {
+                               ret = sparse_merge_blocks(chunk_start,
+                                                         j + 1 - chunk_start);
+                               chunk_start = -1;
                        }
                        ASSERT(!ret);
                }