blob: 22f69ebf092700ce40872ee560772453918d043b [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_F2FS_MKFS_H_
#define THIRD_PARTY_F2FS_MKFS_H_
namespace f2fs {
constexpr uint32_t kChecksumOffset = 4092;
struct MkfsOptions {
// TODO: Add mkfs options
/*
Usage: mkfs.f2fs [options] device [sectors]
[options]:
-l label
-a heap-based allocation [default:0]
-o overprovision ratio [default:5]
-s # of segments per section [default:1]
-z # of sections per zone [default:1]
-e [extention list] e.g. "mp3,gif,mov"
*/
char* label = nullptr;
bool heap_based_allocation = false;
uint32_t overprovision_ratio = 5;
uint32_t num_of_seg_per_sec = 1;
uint32_t num_of_sec_per_zone = 1;
char* extention_list = nullptr;
};
class F2fsMkfs {
public:
explicit F2fsMkfs(std::unique_ptr<f2fs::Bcache> bc, const MkfsOptions& mkfs_options);
~F2fsMkfs() = default;
zx_status_t Mkfs();
private:
std::unique_ptr<f2fs::Bcache> bc_;
[[maybe_unused]] const MkfsOptions& mkfs_options_;
// F2FS Parameter
GlobalParameters params_;
SuperBlock super_block_;
void InitGlobalParameters();
zx_status_t GetDeviceInfo();
zx_status_t FormatDevice();
void AsciiToUnicode(const std::string& in_string, std::u16string* out_string);
inline int F2fsSetBit(uint32_t nr, uint8_t* addr);
int8_t LogBase2(uint32_t num);
void ConfigureExtensionList();
zx_status_t WriteToDisk(void* buf, uint64_t offset, size_t length);
zx_status_t PrepareSuperBlock();
zx_status_t InitSitArea();
zx_status_t InitNatArea();
zx_status_t WriteCheckPointPack();
zx_status_t WriteSuperBlock();
zx_status_t WriteRootInode();
zx_status_t UpdateNatRoot();
zx_status_t AddDefaultDentryRoot();
zx_status_t CreateRootDir();
#if 0 // porting needed
// TODO: Trim support
// int f2fs_trim_device()
#endif
};
} // namespace f2fs
#endif // THIRD_PARTY_F2FS_MKFS_H_