| From 51931263998287532e33fc14f717bb85e609c17e Mon Sep 17 00:00:00 2001 |
| From: Seokhwan Kim <sukka.kim@samsung.com> |
| Date: Thu, 20 May 2021 20:24:38 +0900 |
| Subject: [PATCH] [f2fs] Add fs-management support for f2fs |
| |
| Change-Id: I888db3b24e44502c757b8aaff63b11feb1397a1a |
| --- |
| build/cpp/BUILD.gn | 1 + |
| src/lib/storage/fs_management/cpp/admin.cc | 3 +++ |
| src/lib/storage/fs_management/cpp/fsck.cc | 2 ++ |
| .../fs_management/cpp/include/fs-management/format.h | 9 +++++++++ |
| src/lib/storage/fs_management/cpp/mkfs.cc | 3 +++ |
| src/lib/storage/fs_management/cpp/mount.cc | 4 ++++ |
| 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 +++++-- |
| 12 files changed, 34 insertions(+), 10 deletions(-) |
| |
| diff --git a/build/cpp/BUILD.gn b/build/cpp/BUILD.gn |
| index b3c744656b5..efe4af32535 100644 |
| --- a/build/cpp/BUILD.gn |
| +++ b/build/cpp/BUILD.gn |
| @@ -275,6 +275,7 @@ config("fidl-llcpp-deprecated-raw-channels") { |
| "//src/ui/tools/print-input-report:print-input-report-test-bin", |
| "//src/virtualization/bin/guest:bin", |
| "//src/virtualization/bin/guest_runner:bin", |
| + "//third_party/f2fs:f2fs", |
| "//vendor/*", |
| "//zircon/system/ulib/block-client:block-client", |
| "//zircon/system/ulib/c/test:cdebugdata-test", |
| diff --git a/src/lib/storage/fs_management/cpp/admin.cc b/src/lib/storage/fs_management/cpp/admin.cc |
| index 0323cedf58c..60ff9976c91 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 init_options_t& |
| 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/fsck.cc b/src/lib/storage/fs_management/cpp/fsck.cc |
| index 53ef4e901f6..385d8f7aacd 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 fsck_options_t |
| 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: |
| return ZX_ERR_NOT_SUPPORTED; |
| } |
| 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 f8acc72e088..24675dfe747 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, |
| DISK_FORMAT_BOOTPART, |
| DISK_FORMAT_FXFS, |
| + DISK_FORMAT_F2FS, |
| DISK_FORMAT_COUNT_, |
| } disk_format_t; |
| |
| @@ -39,6 +40,7 @@ static const char* disk_format_string_[DISK_FORMAT_COUNT_] = { |
| [DISK_FORMAT_VBMETA] = "vbmeta", |
| [DISK_FORMAT_BOOTPART] = "bootpart", |
| [DISK_FORMAT_FXFS] = "fxfs", |
| + [DISK_FORMAT_F2FS] = "f2fs", |
| }; |
| |
| static inline const char* disk_format_string(disk_format_t fs_type) { |
| @@ -80,6 +82,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 7d3882829b9..506512aaf51 100644 |
| --- a/src/lib/storage/fs_management/cpp/mkfs.cc |
| +++ b/src/lib/storage/fs_management/cpp/mkfs.cc |
| @@ -117,6 +117,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: |
| return ZX_ERR_NOT_SUPPORTED; |
| } |
| diff --git a/src/lib/storage/fs_management/cpp/mount.cc b/src/lib/storage/fs_management/cpp/mount.cc |
| index 8a81306bd61..1bab8bf86f6 100644 |
| --- a/src/lib/storage/fs_management/cpp/mount.cc |
| +++ b/src/lib/storage/fs_management/cpp/mount.cc |
| @@ -245,6 +245,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/bin/fsck/main.cc b/src/storage/bin/fsck/main.cc |
| index 924a59bdfa2..da78f361538 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 797d826f89d..9d370619483 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 6c5ccc9caaf..7b2dcc2638f 100644 |
| --- a/src/storage/fshost/block-device.cc |
| +++ b/src/storage/fshost/block-device.cc |
| @@ -632,6 +632,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 94fdd9b8d0d..abcfd5da504 100644 |
| --- a/zircon/system/public/zircon/device/vfs.h |
| +++ b/zircon/system/public/zircon/device/vfs.h |
| @@ -54,5 +54,6 @@ typedef struct { |
| #define VFS_TYPE_MINFS 0x6e694d21ul |
| #define VFS_TYPE_MEMFS 0x3e694d21ul |
| #define VFS_TYPE_FACTORYFS 0x1e694d21ul |
| +#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.29.0 |
| |