From 271398ad50d3e5df389b61954c29c92109a927f5 Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Mon, 28 Sep 2015 10:57:47 -0700 Subject: Allow f2fs to reserve bytes for footer when formatting Ticket: SAMBAR-729 Change-Id: I66630d2e24434e5b5587f0b0cb43e3e7543c960c --- roots.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'roots.cpp') diff --git a/roots.cpp b/roots.cpp index 2bd457e..cbea308 100644 --- a/roots.cpp +++ b/roots.cpp @@ -235,24 +235,24 @@ int format_volume(const char* volume) { if (strcmp(v->fs_type, "ext4") == 0) { result = make_ext4fs(v->blk_device, length, volume, sehandle); } else { /* Has to be f2fs because we checked earlier. */ - if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { - LOGE("format_volume: crypt footer + negative length (%zd) not supported on %s\n", length, v->fs_type); - return -1; - } + char bytes_reserved[20], num_sectors[20]; + const char* f2fs_argv[6] = {"mkfs.f2fs", "-t1"}; if (length < 0) { - LOGE("format_volume: negative length (%zd) not supported on %s\n", length, v->fs_type); - return -1; - } - char *num_sectors; - if (asprintf(&num_sectors, "%zd", length / 512) <= 0) { - LOGE("format_volume: failed to create %s command for %s\n", v->fs_type, v->blk_device); - return -1; + snprintf(bytes_reserved, sizeof(bytes_reserved), "%zd", -length); + f2fs_argv[2] = "-r"; + f2fs_argv[3] = bytes_reserved; + f2fs_argv[4] = v->blk_device; + f2fs_argv[5] = NULL; + } else { + /* num_sectors can be zero which mean whole device space */ + snprintf(num_sectors, sizeof(num_sectors), "%zd", length / 512); + f2fs_argv[2] = v->blk_device; + f2fs_argv[3] = num_sectors; + f2fs_argv[4] = NULL; } const char *f2fs_path = "/sbin/mkfs.f2fs"; - const char* const f2fs_argv[] = {"mkfs.f2fs", "-t", "-d1", v->blk_device, num_sectors, NULL}; result = exec_cmd(f2fs_path, (char* const*)f2fs_argv); - free(num_sectors); } if (result != 0) { LOGE("format_volume: make %s failed on %s with %d(%s)\n", v->fs_type, v->blk_device, result, strerror(errno)); -- cgit v1.1