fs: add initial code to create the partition table

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 2448ddcd4e
commit adcda56894
  1. 1
      Makefile
  2. 3
      include/fs/part.h
  3. 40
      source/fs/part.c

@ -24,6 +24,7 @@ obj-y += source/shell/flash.o
obj-y += source/core/flash.o
obj-y += source/fs/block.o
obj-y += source/fs/part.o
obj = $(addprefix $(BUILD)/, $(obj-y))

@ -0,0 +1,3 @@
#pragma once
int part_create(struct flash_dev *dev);

@ -0,0 +1,40 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <flash.h>
#include <macros.h>
#include <fs/block.h>
#include <fs/part.h>
struct part_hdr {
char magic[8];
char rsv[24];
} __attribute__((packed));
struct part_entry {
char label[16];
uint32_t start, end;
uint32_t flags;
uint32_t rsv;
} __attribute__((packed));
#define PART_MAGIC "FL-PART\x7f"
int part_create(struct flash_dev *dev)
{
struct part_hdr hdr;
if (block_is_erased(dev, 0, 4 * KIB) != 0 &&
flash_erase(dev, 0, 4 * KIB) != 0)
return -1;
memset(&hdr, 0, sizeof hdr);
memcpy(hdr.magic, PART_MAGIC, sizeof hdr.magic);
if (flash_write(dev, 0, &hdr, sizeof hdr) != 0)
return -1;
return 0;
}
Loading…
Cancel
Save