blob: 0e459c4a72ec050151438b579d44697905d26060 [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 F2FS_MKFS_H_
#define F2FS_MKFS_H_
namespace f2fs {
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;
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;
};
class F2fsMkfs {
public:
F2fsMkfs(std::unique_ptr<f2fs::Bcache> bc, const MkfsOptions& mkfs_options);
~F2fsMkfs() {}
zx_status_t Mkfs();
private:
std::unique_ptr<f2fs::Bcache> bc_;
[[maybe_unused]] const MkfsOptions& mkfs_options_;
// F2FS Parameter
struct f2fs_global_parameters f2fs_params;
struct f2fs_super_block super_block;
void F2fsInitGlobalParameters();
zx_status_t F2fsGetDeviceInfo();
int8_t F2fsFormatDevice();
void ASCIIToUNICODE(uint16_t* out_buf, uint8_t* in_buf);
inline int F2fsSetBit(unsigned int nr, unsigned char* addr);
int8_t LogBase2(uint32_t num);
void ConfigureExtensionList();
zx_status_t WriteToDisk(void* buf, uint64_t offset, size_t length);
zx_status_t F2fsPrepareSuperBlock();
zx_status_t F2fsInitSitArea();
zx_status_t F2fsInitNatArea();
zx_status_t F2fsWriteCheckPointPack();
zx_status_t F2fsWriteSuperBlock();
zx_status_t F2fsWriteRootInode();
zx_status_t F2fsUpdateNatRoot();
zx_status_t F2fsAddDefaultDentryRoot();
zx_status_t F2fsCreateRootDir();
#if 0 // porting needed
// TODO: Trim support
// int f2fs_trim_device()
#endif
};
} // namespace f2fs
#endif // F2FS_MKFS_H_