Selaa lähdekoodia

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
Christopher Haster 8 vuotta sitten
vanhempi
sitoutus
3b9d6630c8
6 muutettua tiedostoa jossa 340 lisäystä ja 417 poistoa
  1. 1 1
      Makefile
  2. 321 405
      lfs.c
  3. 11 8
      lfs.h
  4. 1 1
      lfs_util.c
  5. 1 1
      lfs_util.h
  6. 5 1
      tests/test_format.sh

+ 1 - 1
Makefile

@@ -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
 	./$<
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 321 - 405
lfs.c


+ 11 - 8
lfs.h

@@ -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;

+ 1 - 1
lfs_util.c

@@ -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,

+ 1 - 1
lfs_util.h

@@ -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);
 
 
 

+ 5 - 1
tests/test_format.sh

@@ -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;

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä