ftl: fix bug in root recovery by marking page descriptors with a magic value

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 23c861eab5
commit dc6365c7f8
  1. 1
      include/ftl.h
  2. 17
      source/ftl/map.c
  3. 4
      source/ftl/map.h

@ -9,6 +9,7 @@ struct ftl_page_group {
} __attribute__((packed));
struct ftl_page_desc {
char magic[4];
uint32_t va;
uint32_t nused_pages;
uint32_t subtrees[32];

@ -77,6 +77,9 @@ int read_page_desc(struct ftl_map *map,
if (flash_read(map->dev, addr + offset, page_desc, sizeof *page_desc) == 0)
return -1;
if (memcmp(page_desc->magic, "page", sizeof page_desc->magic) != 0)
return -1;
return 0;
}
@ -84,7 +87,7 @@ int read_page_desc(struct ftl_map *map,
* increments the head to point to the next free user page.
*/
int write_page_desc(struct ftl_map *map,
const struct ftl_page_desc *page_desc)
struct ftl_page_desc *page_desc)
{
struct ftl_page_group group;
uint32_t group_no, page, addr, offset, head;
@ -106,6 +109,8 @@ int write_page_desc(struct ftl_map *map,
offset = sizeof group + (map->head & ((1 << map->log2_pages_per_group) - 1)) *
sizeof *page_desc;
memcpy(page_desc->magic, "page", sizeof page_desc->magic);
if (flash_write(map->dev, addr + offset, page_desc, sizeof *page_desc) == 0)
return -1;
@ -126,7 +131,7 @@ int write_page_desc(struct ftl_map *map,
* page.
*/
int write_upage(struct ftl_map *map, const void *page,
const struct ftl_page_desc *page_desc)
struct ftl_page_desc *page_desc)
{
if (prepare_head(map) < 0)
return -1;
@ -265,14 +270,10 @@ static int find_root(struct ftl_map *map, uint32_t group)
upage = group << map->log2_pages_per_group;
do {
while (read_page_desc(map, &page_desc, upage) == 0) {
map->root = upage;
upage = next_upage(map, upage);
if (read_page_desc(map, &page_desc, upage) < 0)
return -1;
} while (page_desc.va != UINT32_MAX ||
page_desc.nused_pages == 0);
}
return 0;
}

@ -7,8 +7,8 @@ int read_page_group(struct ftl_map *map,
int read_page_desc(struct ftl_map *map,
struct ftl_page_desc *page_desc, uint32_t upage);
int write_page_desc(struct ftl_map *map,
const struct ftl_page_desc *page_desc);
struct ftl_page_desc *page_desc);
int write_upage(struct ftl_map *map, const void *page,
const struct ftl_page_desc *page_desc);
struct ftl_page_desc *page_desc);
int trace_path(struct ftl_map *map, struct ftl_page_desc *new_page_desc,
uint32_t *page, uint32_t va);

Loading…
Cancel
Save