1 Star 0 Fork 0

beyondsuntong/EagleTree

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
block.cpp 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
Niv Dayan 提交于 2015-02-05 01:32 . bug fixing in gecko
#include <new>
#include <assert.h>
#include <stdio.h>
#include "ssd.h"
#include <sys/types.h>
using namespace ssd;
Block::Block(long physical_address):
pages_invalid(0),
physical_address(physical_address),
data(BLOCK_SIZE, Page()),
pages_valid(0),
erases_remaining(BLOCK_ERASES)
{}
Block::Block():
pages_invalid(0),
physical_address(0),
data(BLOCK_SIZE, Page()),
pages_valid(0),
erases_remaining(BLOCK_ERASES)
{}
enum status Block::read(Event &event)
{
return data[event.get_address().page]._read(event);
}
enum status Block::write(Event &event)
{
if (event.get_address().page > 0 && data[event.get_address().page - 1].get_state() == EMPTY) {
printf("\n");
event.print();
assert(data[event.get_address().page - 1].get_state() != EMPTY);
}
enum status ret = data[event.get_address().page]._write(event);
pages_valid++;
return ret;
}
/* updates Event time_taken
* sets Page statuses to EMPTY
* updates last_erase_time and erases_remaining
* returns 1 for success, 0 for failure */
enum status Block::_erase(Event &event)
{
if(erases_remaining < 1)
{
fprintf(stderr, "Block error: %s: No erases remaining when attempting to erase\n", __func__);
return FAILURE;
}
for(uint i = 0; i < BLOCK_SIZE; i++)
{
//assert(data[i].get_state() == INVALID);
data[i].set_state(EMPTY);
data[i].set_logical_addr(UNDEFINED);
}
event.incr_execution_time(BLOCK_ERASE_DELAY);
erases_remaining--;
pages_valid = 0;
pages_invalid = 0;
return SUCCESS;
}
void Block::invalidate_page(uint page)
{
assert(page < BLOCK_SIZE);
data[page].set_state(INVALID);
pages_invalid++;
pages_valid--;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/beyondsuntong/EagleTree.git
[email protected]:beyondsuntong/EagleTree.git
beyondsuntong
EagleTree
EagleTree
master

搜索帮助