[victoriafalls] Move the block to lba translation to a small wrapper.

Abstract this away into a thin wrapper over the denali client such that
it can be called from other helper classes.
This commit is contained in:
Drew Galbraith 2023-07-05 23:19:25 -07:00
parent a49d13f1d1
commit 21c1a001ea
6 changed files with 83 additions and 35 deletions

View file

@ -4,26 +4,16 @@
#include <glacier/memory/move.h>
#include "fs/ext2/ext2.h"
#include "fs/ext2/ext2_block_reader.h"
class Ext2Driver {
public:
Ext2Driver(ScopedDenaliClient&& denali) : denali_(glcr::Move(denali)) {}
static glcr::ErrorOr<Ext2Driver> Init(ScopedDenaliClient&& denali);
glcr::ErrorCode ProbePartition();
glcr::ErrorOr<MappedMemoryRegion> ReadBlocks(uint64_t block_num,
uint64_t num_blocks) {
return denali_.ReadSectors(SectorsPerBlock() * block_num,
SectorsPerBlock() * num_blocks);
}
uint64_t SectorsPerBlock() { return 1 << (superblock_->log_block_size + 1); }
uint64_t BlockToLba(uint64_t block) { return block * SectorsPerBlock(); }
uint64_t BytesToBlockCount(uint64_t bytes) {
return (bytes - 1) / (1024 << superblock_->log_block_size) + 1;
}
private:
ScopedDenaliClient denali_;
Superblock* superblock_;
Ext2BlockReader ext2_reader_;
Ext2Driver(Ext2BlockReader&& reader) : ext2_reader_(glcr::Move(reader)) {}
};