You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.0 KiB
57 lines
1.0 KiB
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <bitops.h>
|
|
#include <flash.h>
|
|
|
|
#include <fs/mufs.h>
|
|
|
|
struct mufs_super {
|
|
char magic[4];
|
|
uint32_t nblocks;
|
|
uint32_t file_size;
|
|
uint32_t root;
|
|
uint8_t depth;
|
|
} __attribute__((packed));
|
|
|
|
int mufs_mount(struct mufs *fs, struct flash_dev *dev)
|
|
{
|
|
struct mufs_super super;
|
|
|
|
if (!fs || !dev)
|
|
return -1;
|
|
|
|
if (flash_read(dev, 0, &super, sizeof super) == 0)
|
|
return -1;
|
|
|
|
if (memcmp(super.magic, "mufs", 4) != 0)
|
|
return -1;
|
|
|
|
fs->dev = dev;
|
|
fs->nblocks = super.nblocks;
|
|
fs->log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t));
|
|
|
|
fs->root.file_size = super.file_size;
|
|
fs->root.root = super.root;
|
|
fs->root.depth = super.depth;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int mufs_format(struct flash_dev *dev)
|
|
{
|
|
struct mufs_super super;
|
|
|
|
memcpy(super.magic, "mufs", 4);
|
|
super.nblocks = flash_get_capacity(dev) >> dev->log2_block_size;
|
|
|
|
super.file_size = 0;
|
|
super.root = 0;
|
|
super.depth = 0;
|
|
|
|
if (flash_write(dev, 0, &super, sizeof super) == 0)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|