Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3aa5c82 authored by Keith Mok's avatar Keith Mok Committed by Tom Marshall
Browse files

Allow f2fs to reserve bytes for footer when formatting

Ticket: SAMBAR-729
Change-Id: I66630d2e24434e5b5587f0b0cb43e3e7543c960c
parent f3ce5ac7
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -410,17 +410,35 @@ int format_volume(const char* volume, const char* directory) {
            result = exec_cmd(e2fsdroid_argv[0], const_cast<char**>(e2fsdroid_argv));
          }
        } else {   /* Has to be f2fs because we checked earlier. */
            char *bytes_reserved = nullptr;
            char *num_sectors = nullptr;
            const char* f2fs_argv[6] = {"mkfs.f2fs", "-t1"};
            if (length < 0) {
                if (asprintf(&bytes_reserved, "%zd", -length) <= 0) {
                    LOG(ERROR) << "format_volume: failed to create " << v->fs_type
                               << " command for " << v->blk_device;
                    return -1;
                }
                f2fs_argv[2] = "-r";
                f2fs_argv[3] = bytes_reserved;
                f2fs_argv[4] = v->blk_device;
                f2fs_argv[5] = nullptr;
            } else {
                /* num_sectors can be zero which mean whole device space */
                if (length >= 512 && asprintf(&num_sectors, "%zd", length / 512) <= 0) {
                    LOG(ERROR) << "format_volume: failed to create " << v->fs_type
                               << " command for " << v->blk_device;
                    return -1;
                }
                snprintf(num_sectors, sizeof(num_sectors), "%zd", length / 512);
                f2fs_argv[2] = v->blk_device;
                f2fs_argv[3] = num_sectors;
                f2fs_argv[4] = nullptr;
            }
            const char *f2fs_path = "/sbin/mkfs.f2fs";
            const char* const f2fs_argv[] = {"mkfs.f2fs", "-t", "-d1", v->blk_device, num_sectors, nullptr};

            result = exec_cmd(f2fs_path, (char* const*)f2fs_argv);
            free(num_sectors);
            free(bytes_reserved);
        }
        if (result != 0) {
            PLOG(ERROR) << "format_volume: make " << v->fs_type << " failed on " << v->blk_device;