2023-07-05 23:19:25 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-15 09:47:32 -08:00
|
|
|
#include <denali/denali.yunq.client.h>
|
2023-08-01 10:39:26 -07:00
|
|
|
#include <glacier/memory/shared_ptr.h>
|
2023-07-05 23:19:25 -07:00
|
|
|
#include <glacier/status/error_or.h>
|
|
|
|
#include <mammoth/memory_region.h>
|
2023-11-15 09:47:32 -08:00
|
|
|
#include <yellowstone/yellowstone.yunq.h>
|
2023-07-05 23:19:25 -07:00
|
|
|
|
|
|
|
#include "fs/ext2/ext2.h"
|
|
|
|
|
2023-07-06 09:58:26 -07:00
|
|
|
/* Simple Wrapper class around the denali client to translate blocks to sectors.
|
|
|
|
*
|
|
|
|
* By necessity contains the Ext Superblock (to make the translation
|
|
|
|
* calculation).
|
|
|
|
* */
|
2023-07-05 23:19:25 -07:00
|
|
|
class Ext2BlockReader {
|
|
|
|
public:
|
2023-08-01 10:39:26 -07:00
|
|
|
static glcr::ErrorOr<glcr::SharedPtr<Ext2BlockReader>> Init(
|
2023-11-15 09:47:32 -08:00
|
|
|
const DenaliInfo& denali_info);
|
2023-07-05 23:19:25 -07:00
|
|
|
|
2023-07-06 09:58:26 -07:00
|
|
|
// TODO: Consider creating a new class wrapper with these computations.
|
2023-07-05 23:19:25 -07:00
|
|
|
Superblock* GetSuperblock();
|
2023-07-06 09:58:26 -07:00
|
|
|
uint64_t BlockSize();
|
|
|
|
uint64_t NumberOfBlockGroups();
|
|
|
|
uint64_t BgdtBlockNum();
|
|
|
|
uint64_t BgdtBlockSize();
|
|
|
|
uint64_t InodeSize();
|
|
|
|
// FIXME: This probably needs to take into account the block group number
|
|
|
|
// because the last table will likely be smaller.
|
|
|
|
uint64_t InodeTableBlockSize();
|
2023-07-05 23:19:25 -07:00
|
|
|
|
2023-11-19 20:33:15 -08:00
|
|
|
glcr::ErrorOr<OwnedMemoryRegion> ReadBlock(uint64_t block_number);
|
|
|
|
glcr::ErrorOr<OwnedMemoryRegion> ReadBlocks(uint64_t block_number,
|
|
|
|
uint64_t num_blocks);
|
2023-07-05 23:19:25 -07:00
|
|
|
|
2023-11-19 20:33:15 -08:00
|
|
|
glcr::ErrorOr<OwnedMemoryRegion> ReadBlocks(
|
2023-11-15 09:47:32 -08:00
|
|
|
const glcr::Vector<uint64_t>& block_list);
|
|
|
|
|
2023-07-05 23:19:25 -07:00
|
|
|
private:
|
2023-11-15 09:47:32 -08:00
|
|
|
DenaliClient denali_;
|
|
|
|
uint64_t device_id_;
|
|
|
|
uint64_t lba_offset_;
|
2023-11-19 20:33:15 -08:00
|
|
|
OwnedMemoryRegion super_block_region_;
|
2023-07-05 23:19:25 -07:00
|
|
|
|
2023-11-15 09:47:32 -08:00
|
|
|
Ext2BlockReader(DenaliClient&& denali, uint64_t device_id,
|
2023-11-19 20:33:15 -08:00
|
|
|
uint64_t lba_offset, OwnedMemoryRegion&& super_block);
|
2023-07-06 09:58:26 -07:00
|
|
|
|
|
|
|
uint64_t SectorsPerBlock();
|
2023-07-05 23:19:25 -07:00
|
|
|
};
|