| From 61607c904f61947f52d0a92a8892c9ec8d1dccfb Mon Sep 17 00:00:00 2001 |
| From: Seokhwan Kim <sukka.kim@samsung.com> |
| Date: Fri, 23 Jul 2021 09:00:56 +0900 |
| Subject: [PATCH 1/5] [f2fs] Add fs-management support for f2fs |
| |
| Change-Id: Ia3248bdcab038f09fe4454caeaf9dfab2bbdbe12 |
| --- |
| src/lib/storage/fs_management/cpp/admin.cc | 3 +++ |
| src/lib/storage/fs_management/cpp/format.cc | 1 + |
| src/lib/storage/fs_management/cpp/fsck.cc | 2 ++ |
| .../fs_management/cpp/include/fs-management/format.h | 8 ++++++++ |
| src/lib/storage/fs_management/cpp/mkfs.cc | 3 +++ |
| src/lib/storage/fs_management/cpp/mount.cc | 4 ++++ |
| src/storage/BUILD.gn | 1 + |
| src/storage/bin/fsck/main.cc | 6 ++---- |
| src/storage/bin/mkfs/main.cc | 6 ++---- |
| src/storage/bundles/BUILD.gn | 1 + |
| src/storage/fshost/block-device.cc | 1 + |
| zircon/system/public/zircon/device/vfs.h | 1 + |
| zircon/system/ulib/fs-test-utils/perftest.cc | 7 +++++-- |
| 13 files changed, 34 insertions(+), 10 deletions(-) |
| |
| diff --git a/src/lib/storage/fs_management/cpp/admin.cc b/src/lib/storage/fs_management/cpp/admin.cc |
| index 689d9d54434..6f4586b409d 100644 |
| --- a/src/lib/storage/fs_management/cpp/admin.cc |
| +++ b/src/lib/storage/fs_management/cpp/admin.cc |
| @@ -128,6 +128,9 @@ zx::status<> FsInit(zx::channel device, disk_format_t df, const InitOptions& opt |
| case DISK_FORMAT_FXFS: |
| return InitNativeFs(fs_management::GetBinaryPath("fxfs").c_str(), std::move(device), options, |
| std::move(outgoing_directory)); |
| + case DISK_FORMAT_F2FS: |
| + return InitNativeFs(fs_management::GetBinaryPath("f2fs").c_str(), std::move(device), options, |
| + std::move(outgoing_directory)); |
| case DISK_FORMAT_BLOBFS: |
| return InitNativeFs(fs_management::GetBinaryPath("blobfs").c_str(), std::move(device), |
| options, std::move(outgoing_directory)); |
| diff --git a/src/lib/storage/fs_management/cpp/format.cc b/src/lib/storage/fs_management/cpp/format.cc |
| index 5892eefe997..171394d7e25 100644 |
| --- a/src/lib/storage/fs_management/cpp/format.cc |
| +++ b/src/lib/storage/fs_management/cpp/format.cc |
| @@ -68,6 +68,7 @@ __EXPORT const char* disk_format_string(disk_format_t fs_type) { |
| [DISK_FORMAT_VBMETA] = "vbmeta", |
| [DISK_FORMAT_BOOTPART] = "bootpart", |
| [DISK_FORMAT_FXFS] = "fxfs", |
| + [DISK_FORMAT_F2FS] = "f2fs", |
| }; |
| |
| if (fs_type < DISK_FORMAT_COUNT_) { |
| diff --git a/src/lib/storage/fs_management/cpp/fsck.cc b/src/lib/storage/fs_management/cpp/fsck.cc |
| index 354aea35839..5eaa5af5f37 100644 |
| --- a/src/lib/storage/fs_management/cpp/fsck.cc |
| +++ b/src/lib/storage/fs_management/cpp/fsck.cc |
| @@ -94,6 +94,8 @@ zx_status_t fsck(const char* device_path, disk_format_t df, const FsckOptions& o |
| return FsckFat(device_path, options, cb); |
| case DISK_FORMAT_BLOBFS: |
| return FsckNativeFs(device_path, options, cb, fs_management::GetBinaryPath("blobfs").c_str()); |
| + case DISK_FORMAT_F2FS: |
| + return FsckNativeFs(device_path, options, cb, fs_management::GetBinaryPath("f2fs").c_str()); |
| default: |
| auto* format = fs_management::CustomDiskFormat::Get(df); |
| if (format == nullptr) { |
| diff --git a/src/lib/storage/fs_management/cpp/include/fs-management/format.h b/src/lib/storage/fs_management/cpp/include/fs-management/format.h |
| index 8d8c0fecb6d..56b2d935a99 100644 |
| --- a/src/lib/storage/fs_management/cpp/include/fs-management/format.h |
| +++ b/src/lib/storage/fs_management/cpp/include/fs-management/format.h |
| @@ -23,6 +23,7 @@ typedef enum disk_format_type { |
| DISK_FORMAT_VBMETA = 10, |
| DISK_FORMAT_BOOTPART = 11, |
| DISK_FORMAT_FXFS = 12, |
| + DISK_FORMAT_F2FS = 13, |
| DISK_FORMAT_COUNT_, |
| } disk_format_t; |
| |
| @@ -63,6 +64,13 @@ static const uint8_t vbmeta_magic[4] = { |
| '0', |
| }; |
| |
| +static const uint8_t f2fs_magic[4] = { |
| + 0x10, |
| + 0x20, |
| + 0xf5, |
| + 0xf2, |
| +}; |
| + |
| disk_format_t detect_disk_format(int fd); |
| disk_format_t detect_disk_format_log_unknown(int fd); |
| |
| diff --git a/src/lib/storage/fs_management/cpp/mkfs.cc b/src/lib/storage/fs_management/cpp/mkfs.cc |
| index fc9423798e5..93566c917be 100644 |
| --- a/src/lib/storage/fs_management/cpp/mkfs.cc |
| +++ b/src/lib/storage/fs_management/cpp/mkfs.cc |
| @@ -116,6 +116,9 @@ zx_status_t mkfs(const char* device_path, disk_format_t df, LaunchCallback cb, |
| case DISK_FORMAT_BLOBFS: |
| return MkfsNativeFs(fs_management::GetBinaryPath("blobfs").c_str(), device_path, cb, options, |
| true); |
| + case DISK_FORMAT_F2FS: |
| + return MkfsNativeFs(fs_management::GetBinaryPath("f2fs").c_str(), device_path, cb, options, |
| + true); |
| default: |
| auto* format = fs_management::CustomDiskFormat::Get(df); |
| if (format == nullptr) { |
| diff --git a/src/lib/storage/fs_management/cpp/mount.cc b/src/lib/storage/fs_management/cpp/mount.cc |
| index 844def8a3b7..0a6fec3f492 100644 |
| --- a/src/lib/storage/fs_management/cpp/mount.cc |
| +++ b/src/lib/storage/fs_management/cpp/mount.cc |
| @@ -215,6 +215,10 @@ disk_format_t detect_disk_format_impl(int fd, DiskFormatLogVerbosity verbosity) |
| return DISK_FORMAT_MBR; |
| } |
| |
| + if (!memcmp(&data[1024], f2fs_magic, sizeof(f2fs_magic))) { |
| + return DISK_FORMAT_F2FS; |
| + } |
| + |
| if (verbosity == DiskFormatLogVerbosity::Verbose) { |
| // Log a hexdump of the bytes we looked at and didn't find any magic in. |
| fprintf(stderr, "detect_disk_format: did not recognize format. Looked at:\n"); |
| diff --git a/src/storage/BUILD.gn b/src/storage/BUILD.gn |
| index 0449185c269..788923b0598 100644 |
| --- a/src/storage/BUILD.gn |
| +++ b/src/storage/BUILD.gn |
| @@ -28,6 +28,7 @@ group("tests") { |
| "stress-tests", |
| "tools/blobfs-compression/test:tests", |
| "volume_image:tests", |
| + "//third_party/f2fs:tests", |
| ] |
| } |
| |
| diff --git a/src/storage/bin/fsck/main.cc b/src/storage/bin/fsck/main.cc |
| index e0582edabe3..7a7b93c31c2 100644 |
| --- a/src/storage/bin/fsck/main.cc |
| +++ b/src/storage/bin/fsck/main.cc |
| @@ -25,10 +25,8 @@ struct { |
| const char* name; |
| disk_format_t df; |
| } FILESYSTEMS[] = { |
| - {"blobfs", DISK_FORMAT_BLOBFS}, |
| - {"minfs", DISK_FORMAT_MINFS}, |
| - {"fat", DISK_FORMAT_FAT}, |
| - {"factoryfs", DISK_FORMAT_FACTORYFS}, |
| + {"blobfs", DISK_FORMAT_BLOBFS}, {"minfs", DISK_FORMAT_MINFS}, {"fat", DISK_FORMAT_FAT}, |
| + {"factoryfs", DISK_FORMAT_FACTORYFS}, {"f2fs", DISK_FORMAT_F2FS}, |
| }; |
| |
| int usage(void) { |
| diff --git a/src/storage/bin/mkfs/main.cc b/src/storage/bin/mkfs/main.cc |
| index ba8b9bfb344..1d82a1ebf11 100644 |
| --- a/src/storage/bin/mkfs/main.cc |
| +++ b/src/storage/bin/mkfs/main.cc |
| @@ -28,10 +28,8 @@ struct { |
| const char* name; |
| disk_format_t df; |
| } FILESYSTEMS[] = { |
| - {"blobfs", DISK_FORMAT_BLOBFS}, |
| - {"minfs", DISK_FORMAT_MINFS}, |
| - {"fat", DISK_FORMAT_FAT}, |
| - {"factoryfs", DISK_FORMAT_FACTORYFS}, |
| + {"blobfs", DISK_FORMAT_BLOBFS}, {"minfs", DISK_FORMAT_MINFS}, {"fat", DISK_FORMAT_FAT}, |
| + {"factoryfs", DISK_FORMAT_FACTORYFS}, {"f2fs", DISK_FORMAT_F2FS}, |
| }; |
| |
| int usage(void) { |
| diff --git a/src/storage/bundles/BUILD.gn b/src/storage/bundles/BUILD.gn |
| index 1cb78bbb091..30873f04db5 100644 |
| --- a/src/storage/bundles/BUILD.gn |
| +++ b/src/storage/bundles/BUILD.gn |
| @@ -10,6 +10,7 @@ group("bootstrap") { |
| "//src/storage/bin/mkfs", |
| "//src/storage/blobfs:decompressor-sandbox", |
| "//src/storage/fshost:bootfs", |
| + "//third_party/f2fs/tools:f2fs", |
| ] |
| } |
| |
| diff --git a/src/storage/fshost/block-device.cc b/src/storage/fshost/block-device.cc |
| index 61c54354fe9..b597b228cf6 100644 |
| --- a/src/storage/fshost/block-device.cc |
| +++ b/src/storage/fshost/block-device.cc |
| @@ -754,6 +754,7 @@ zx_status_t BlockDeviceInterface::Add(bool format_on_corruption) { |
| case DISK_FORMAT_VBMETA: |
| case DISK_FORMAT_UNKNOWN: |
| case DISK_FORMAT_FXFS: |
| + case DISK_FORMAT_F2FS: |
| case DISK_FORMAT_COUNT_: |
| return ZX_ERR_NOT_SUPPORTED; |
| } |
| diff --git a/zircon/system/public/zircon/device/vfs.h b/zircon/system/public/zircon/device/vfs.h |
| index 27d10b7f0c3..4c1cdc0983e 100644 |
| --- a/zircon/system/public/zircon/device/vfs.h |
| +++ b/zircon/system/public/zircon/device/vfs.h |
| @@ -57,5 +57,6 @@ typedef struct { |
| #define VFS_TYPE_MEMFS 0x3e694d21ul |
| #define VFS_TYPE_FACTORYFS 0x1e694d21ul |
| #define VFS_TYPE_FXFS 0x73667866ul |
| +#define VFS_TYPE_F2FS 0xfe694d21ul |
| |
| #endif // SYSROOT_ZIRCON_DEVICE_VFS_H_ |
| diff --git a/zircon/system/ulib/fs-test-utils/perftest.cc b/zircon/system/ulib/fs-test-utils/perftest.cc |
| index ba5b956777a..d7a607bf265 100644 |
| --- a/zircon/system/ulib/fs-test-utils/perftest.cc |
| +++ b/zircon/system/ulib/fs-test-utils/perftest.cc |
| @@ -50,7 +50,7 @@ Usage: |
| |
| --fs FS_NAME Will use FS_NAME filesystem to format |
| the block device. |
| - (Options: blobfs, minfs) |
| + (Options: blobfs, minfs, f2fs) |
| |
| --seed SEED An unsigned integer to initialize |
| pseudo-ramdom number generator. |
| @@ -356,9 +356,12 @@ bool ParseCommandLineArgs(int argc, const char* const* argv, FixtureOptions* fix |
| fixture_options->fs_type = DISK_FORMAT_MINFS; |
| } else if (strcmp(optarg, "blobfs") == 0) { |
| fixture_options->fs_type = DISK_FORMAT_BLOBFS; |
| + } else if (strcmp(optarg, "f2fs") == 0) { |
| + fixture_options->fs_type = DISK_FORMAT_F2FS; |
| } else { |
| LOG_ERROR(ZX_ERR_INVALID_ARGS, |
| - "Unknown disk_format %s. Support values are minfs and blobfs.\n", optarg); |
| + "Unknown disk_format %s. Support values are f2fs, minfs and blobfs.\n", |
| + optarg); |
| return false; |
| } |
| break; |
| -- |
| 2.25.1 |
| |