parent
e131d77cf5
commit
19cd9d185f
@ -0,0 +1,12 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
struct flash_dev; |
||||||
|
|
||||||
|
struct mufs { |
||||||
|
struct flash_dev *dev; |
||||||
|
uint32_t nblocks; |
||||||
|
uint32_t root; |
||||||
|
}; |
||||||
|
|
||||||
|
int mufs_mount(struct mufs *fs, struct flash_dev *dev); |
||||||
|
int mufs_format(struct flash_dev *dev); |
@ -0,0 +1,47 @@ |
|||||||
|
#include <stdint.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
|
||||||
|
#include <flash.h> |
||||||
|
|
||||||
|
#include <fs/mufs.h> |
||||||
|
|
||||||
|
struct mufs_super { |
||||||
|
char magic[4]; |
||||||
|
uint32_t nblocks; |
||||||
|
uint32_t root; |
||||||
|
} __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->root = super.root; |
||||||
|
|
||||||
|
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.root = 0; |
||||||
|
|
||||||
|
if (flash_write(dev, 0, &super, sizeof super) == 0) |
||||||
|
return -1; |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
Loading…
Reference in new issue