Restructured directory code

After quite a bit of prototyping, settled on the following functions:
- lfs_dir_alloc  - create a new dir
- lfs_dir_fetch  - load and check a dir pair from disk
- lfs_dir_commit - save a dir pair to disk
- lfs_dir_shift  - shrink a dir pair to disk
- lfs_dir_append - add a dir entry, creating dirs if needed
- lfs_dir_remove - remove a dir entry, dropping dirs if needed

Additionally, followed through with a few other tweaks
This commit is contained in:
Christopher Haster
2017-04-17 22:27:06 -05:00
parent bd817abb00
commit 3b9d6630c8
6 changed files with 441 additions and 598 deletions

View File

@@ -31,7 +31,7 @@ size: $(OBJ)
$(SIZE) -t $^
.SUFFIXES:
test: test_format test_dirs test_files test_alloc test_orphan test_paths
test: test_format test_dirs test_files test_alloc test_paths test_orphan
test_%: tests/test_%.sh
./$<

950
lfs.c

File diff suppressed because it is too large Load Diff

19
lfs.h
View File

@@ -24,8 +24,9 @@ enum lfs_error {
};
enum lfs_type {
LFS_TYPE_REG = 1,
LFS_TYPE_DIR = 2,
LFS_TYPE_REG = 0x01,
LFS_TYPE_DIR = 0x02,
LFS_TYPE_SUPERBLOCK = 0x10,
};
enum lfs_open_flags {
@@ -58,7 +59,7 @@ struct lfs_info {
};
typedef struct lfs_entry {
lfs_block_t dir[2];
lfs_block_t pair[2];
lfs_off_t off;
struct lfs_disk_entry {
@@ -100,14 +101,17 @@ typedef struct lfs_dir {
} lfs_dir_t;
typedef struct lfs_superblock {
lfs_block_t pair[2];
lfs_block_t dir[2]; //TODO rm me?
lfs_off_t off;
struct lfs_disk_superblock {
uint32_t rev;
uint32_t size;
lfs_block_t root[2];
uint16_t type;
uint16_t len;
uint32_t version;
char magic[8];
uint32_t block_size;
uint32_t block_count;
lfs_block_t root[2];
} d;
} lfs_superblock_t;
@@ -123,7 +127,6 @@ typedef struct lfs {
const struct lfs_bd_ops *bd_ops;
lfs_block_t root[2];
lfs_block_t cwd[2];
struct {
lfs_block_t begin;
lfs_block_t end;

View File

@@ -7,7 +7,7 @@
#include "lfs_util.h"
uint32_t lfs_crc(const void *buffer, lfs_size_t size, uint32_t crc) {
uint32_t lfs_crc(uint32_t crc, lfs_size_t size, const void *buffer) {
static const uint32_t rtable[16] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,

View File

@@ -31,7 +31,7 @@ static inline int lfs_scmp(uint32_t a, uint32_t b) {
return (int)(unsigned)(a - b);
}
uint32_t lfs_crc(const void *buffer, lfs_size_t size, uint32_t crc);
uint32_t lfs_crc(uint32_t crc, lfs_size_t size, const void *buffer);

View File

@@ -11,12 +11,16 @@ TEST
echo "--- Invalid superblocks ---"
ln -f -s /dev/null blocks/0
ln -f -s /dev/null blocks/1
tests/test.py << TEST
lfs_format(&lfs, &config) => LFS_ERROR_CORRUPT;
TEST
rm blocks/0
rm blocks/0 blocks/1
echo "--- Basic mounting ---"
tests/test.py << TEST
lfs_format(&lfs, &config) => 0;
TEST
tests/test.py << TEST
lfs_mount(&lfs, &config) => 0;
lfs_unmount(&lfs) => 0;