|
|
@ -16,7 +16,7 @@ namespace gp { |
|
|
|
template<size_t sz> |
|
|
|
class memory_vdisk { |
|
|
|
static_assert(sz%128 == 0, "in memory disk expects 128 bytes page alignment"); |
|
|
|
k">alignas(128) gp::array<uint8_t, sz> data; |
|
|
|
gp::array<uint8_t, sz> data{gp::zero_t{}}; |
|
|
|
|
|
|
|
public: |
|
|
|
gp::buffer<uint8_t> read(gp::buffer<uint8_t> buffer, uint64_t offset) { |
|
|
@ -62,7 +62,7 @@ namespace gp { |
|
|
|
class tagfs { |
|
|
|
vdisk_ptr disk; |
|
|
|
constexpr static size_t page_size = gp::remove_reference<decltype(*disk)>::type::page_size(); |
|
|
|
const gp::array<uint8_t, page_size> empty_page; |
|
|
|
constexpr static gp::array<uint8_t, page_size> empty_page{gp::zero_t{}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,18 +82,17 @@ namespace gp { |
|
|
|
public: |
|
|
|
tagfs(vdisk_ptr&& _disk) |
|
|
|
: disk(gp::forward<vdisk_ptr>(disk)) |
|
|
|
, empty_page{[](){return 0;}} |
|
|
|
{} |
|
|
|
|
|
|
|
private: |
|
|
|
disk_root get_disk_root() { |
|
|
|
gp::array<disk_root, 1> vret; |
|
|
|
return *disk->read(vret.as_buffer().template cast<uint8_t>(), 0).template cast<disk_root>().begin(); |
|
|
|
disk_root vret; |
|
|
|
disk->read(gp::buffer<disk_root>{&vret, 1}.template cast<uint8_t>(), 0); |
|
|
|
return vret; |
|
|
|
} |
|
|
|
|
|
|
|
void set_disk_root(disk_root& root) { |
|
|
|
gp::array<disk_root, 1> vpar{root}; |
|
|
|
disk->write(vpar.as_buffer().template cast<uint8_t>(), 0); |
|
|
|
disk->write(gp::buffer<disk_root>{&root, 1}.template cast<uint8_t>(), 0); |
|
|
|
} |
|
|
|
|
|
|
|
gp::optional<uint64_t> try_set_bit(gp::buffer<uint8_t> page) { |
|
|
@ -193,36 +192,36 @@ namespace gp { |
|
|
|
|
|
|
|
return {allocator_pages, datapage_count}; |
|
|
|
} |
|
|
|
public: |
|
|
|
void format() { |
|
|
|
auto sz = disk->size(); |
|
|
|
auto page_sz = page_size; |
|
|
|
auto page_count = sz /page_sz; |
|
|
|
auto remaining_pages = page_count; |
|
|
|
|
|
|
|
disk_root root; |
|
|
|
// tagmebro
|
|
|
|
root.magic = 0x7461676D6562726F; |
|
|
|
root.page_count = page_count; |
|
|
|
root.first_allocator_page = 1; |
|
|
|
root.allocator_shuttle = 1; |
|
|
|
|
|
|
|
// Removing the root page
|
|
|
|
remaining_pages -= 1; |
|
|
|
|
|
|
|
// calculating datapages
|
|
|
|
auto [allocator_pages, datapage_count] = split_pages(remaining_pages); |
|
|
|
static_assert(split_pages(page_size*8+1).first == 1, "ideal 1 allocator page split doesn't work"); |
|
|
|
static_assert(split_pages(page_size*8+2).first == 2, "worst 2 allocator page split doesn't work"); |
|
|
|
|
|
|
|
root.allocator_page_count = allocator_pages; |
|
|
|
|
|
|
|
for(uint64_t offset = 0; offset < allocator_pages; ++offset) { |
|
|
|
clear_page(root.first_allocator_page); |
|
|
|
} |
|
|
|
|
|
|
|
void format() { |
|
|
|
auto sz = disk->size(); |
|
|
|
auto page_sz = page_size; |
|
|
|
auto page_count = sz /page_sz; |
|
|
|
auto remaining_pages = page_count; |
|
|
|
|
|
|
|
disk_root root; |
|
|
|
// tagmebro
|
|
|
|
root.magic = 0x7461676D6562726F; |
|
|
|
root.page_count = page_count; |
|
|
|
root.first_allocator_page = 1; |
|
|
|
root.allocator_shuttle = 1; |
|
|
|
|
|
|
|
// Removing the root page
|
|
|
|
remaining_pages -= 1; |
|
|
|
|
|
|
|
// calculating datapages
|
|
|
|
auto [allocator_pages, datapage_count] = split_pages(remaining_pages); |
|
|
|
static_assert(split_pages(page_size*8+1).first == 1, "ideal 1 allocator page split doesn't work"); |
|
|
|
static_assert(split_pages(page_size*8+2).first == 2, "worst 2 allocator page split doesn't work"); |
|
|
|
|
|
|
|
root.allocator_page_count = allocator_pages; |
|
|
|
|
|
|
|
for(uint64_t offset = 0; offset < allocator_pages; ++offset) { |
|
|
|
clear_page(root.first_allocator_page); |
|
|
|
root.tag_list_node = 0; |
|
|
|
set_disk_root(root); |
|
|
|
} |
|
|
|
|
|
|
|
root.tag_list_node = 0; |
|
|
|
set_disk_root(root); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |