From 4358262b757a39fe7939369be4afa6869e8caa3a Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Mon, 2 Apr 2018 13:37:35 -0700 Subject: mkfs.f2fs: specify sector size for target image size The total sectors that we want to format is used in different meanings from various users. This notifies its size based on 4096 bytes explicitly. Bug: 76407663 Change-Id: I3392646648264ad1ca78e4b87240edc9385a0cc4 Merged-In: I3392646648264ad1ca78e4b87240edc9385a0cc4 Reported-by: katao@xiaomi.com Signed-off-by: Jaegeuk Kim --- roots.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/roots.cpp b/roots.cpp index 9ff5186c1..8907bbd9b 100644 --- a/roots.cpp +++ b/roots.cpp @@ -324,19 +324,34 @@ int format_volume(const char* volume, const char* directory) { } // Has to be f2fs because we checked earlier. + static constexpr int kSectorSize = 4096; std::string cmd("/sbin/mkfs.f2fs"); - std::vector make_f2fs_cmd = { cmd, "-d1", "-f", "-O", - "encrypt", "-O", "quota", v->blk_device }; - if (length >= 512) { - make_f2fs_cmd.push_back(std::to_string(length / 512)); + // clang-format off + std::vector make_f2fs_cmd = { + cmd, + "-d1", + "-f", + "-O", "encrypt", + "-O", "quota", + "-w", std::to_string(kSectorSize), + v->blk_device, + }; + // clang-format on + if (length >= kSectorSize) { + make_f2fs_cmd.push_back(std::to_string(length / kSectorSize)); } int result = exec_cmd(make_f2fs_cmd); if (result == 0 && directory != nullptr) { cmd = "/sbin/sload.f2fs"; + // clang-format off std::vector sload_f2fs_cmd = { - cmd, "-f", directory, "-t", volume, v->blk_device, + cmd, + "-f", directory, + "-t", volume, + v->blk_device, }; + // clang-format on result = exec_cmd(sload_f2fs_cmd); } if (result != 0) { -- cgit v1.2.3 From 848f227eea524a48208bdd4181f90fb63a31ed2b Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Fri, 8 Dec 2017 13:19:23 -0800 Subject: f2fs: support f2fs by setting unmovable bit for package file This enables to use uncrypt for f2fs update-on-reboot. It requires kernel patch named: "f2fs: add an ioctl to disable GC for specific file" If any operation fails during uncrypt, please delete package file as soon as possible, and create the file again to move forward. IOWs, don't leave the package file for a long time. Bug: 70309376 Bug: 30170612 Change-Id: I3b4233e7da756f107be35364521699deaf2e7139 Merged-In: I3b4233e7da756f107be35364521699deaf2e7139 Signed-off-by: Jaegeuk Kim --- uncrypt/uncrypt.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index 645faadbf..bb43c2c4a 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -172,10 +172,14 @@ static struct fstab* read_fstab() { return fstab; } -static const char* find_block_device(const char* path, bool* encryptable, bool* encrypted) { +static const char* find_block_device(const char* path, bool* encryptable, bool* encrypted, bool *f2fs_fs) { // Look for a volume whose mount point is the prefix of path and // return its block device. Set encrypted if it's currently // encrypted. + + // ensure f2fs_fs is set to 0 first. + if (f2fs_fs) + *f2fs_fs = false; for (int i = 0; i < fstab->num_entries; ++i) { struct fstab_rec* v = &fstab->recs[i]; if (!v->mount_point) { @@ -192,6 +196,8 @@ static const char* find_block_device(const char* path, bool* encryptable, bool* *encrypted = true; } } + if (f2fs_fs && strcmp(v->fs_type, "f2fs") == 0) + *f2fs_fs = true; return v->blk_device; } } @@ -244,7 +250,7 @@ static int retry_fibmap(const int fd, const char* name, int* block, const int he } static int produce_block_map(const char* path, const char* map_file, const char* blk_dev, - bool encrypted, int socket) { + bool encrypted, bool f2fs_fs, int socket) { std::string err; if (!android::base::RemoveFileIfExists(map_file, &err)) { LOG(ERROR) << "failed to remove the existing map file " << map_file << ": " << err; @@ -307,6 +313,17 @@ static int produce_block_map(const char* path, const char* map_file, const char* } } +#ifndef F2FS_IOC_SET_DONTMOVE +#ifndef F2FS_IOCTL_MAGIC +#define F2FS_IOCTL_MAGIC 0xf5 +#endif +#define F2FS_IOC_SET_DONTMOVE _IO(F2FS_IOCTL_MAGIC, 13) +#endif + if (f2fs_fs && ioctl(fd, F2FS_IOC_SET_DONTMOVE) < 0) { + PLOG(ERROR) << "Failed to set non-movable file for f2fs: " << path << " on " << blk_dev; + return kUncryptIoctlError; + } + off64_t pos = 0; int last_progress = 0; while (pos < sb.st_size) { @@ -458,7 +475,8 @@ static int uncrypt(const char* input_path, const char* map_file, const int socke bool encryptable; bool encrypted; - const char* blk_dev = find_block_device(path, &encryptable, &encrypted); + bool f2fs_fs; + const char* blk_dev = find_block_device(path, &encryptable, &encrypted, &f2fs_fs); if (blk_dev == nullptr) { LOG(ERROR) << "failed to find block device for " << path; return kUncryptBlockDeviceFindError; @@ -479,7 +497,7 @@ static int uncrypt(const char* input_path, const char* map_file, const int socke // and /sdcard we leave the file alone. if (strncmp(path, "/data/", 6) == 0) { LOG(INFO) << "writing block map " << map_file; - return produce_block_map(path, map_file, blk_dev, encrypted, socket); + return produce_block_map(path, map_file, blk_dev, encrypted, f2fs_fs, socket); } return 0; -- cgit v1.2.3