fs: add initial code to create the partition table
This commit is contained in:
parent
2448ddcd4e
commit
adcda56894
3 changed files with 44 additions and 0 deletions
40
source/fs/part.c
Normal file
40
source/fs/part.c
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue