#include #include #include #include #include #include #include #include #include "dir.h" struct mufs_super { char magic[4]; uint32_t nblocks; struct mufs_dtree 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->log2_nentries = fs->dev->log2_block_size - ilog2(sizeof(uint32_t)); fs->root.fs = fs; fs->root.va = offsetof(struct mufs_super, root) + 1; fs->root.file_size = super.root.file_size; fs->root.root = super.root.root; fs->root.depth = super.root.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.root.file_size = 0; super.root.root = 0; super.root.depth = 0; if (flash_write(dev, 0, &super, sizeof super) == 0) return -1; return 0; }