Эх сурвалжийг харах

Merge branch 'master' into test-revamp

Christopher Haster 5 жил өмнө
parent
commit
7257681f5d
4 өөрчлөгдсөн 44 нэмэгдсэн , 22 устгасан
  1. 3 0
      README.md
  2. 9 9
      SPEC.md
  3. 15 0
      lfs.c
  4. 17 13
      lfs_util.h

+ 3 - 0
README.md

@@ -115,6 +115,9 @@ the filesystem until sync or close is called on the file.
 
 ## Other notes
 
+Littlefs is written in C, and specifically should compile with any compiler
+that conforms to the `C99` standard.
+
 All littlefs calls have the potential to return a negative error code. The
 errors can be either one of those found in the `enum lfs_error` in
 [lfs.h](lfs.h), or an error returned by the user's block device operations.

+ 9 - 9
SPEC.md

@@ -289,8 +289,8 @@ Layout of the name tag:
 ```
         tag                          data
 [--      32      --][---        variable length        ---]
-[1| 3| 8 | 10 | 10 ][---            (size)             ---]
- ^  ^  ^    ^    ^- size               ^- file name
+[1| 3| 8 | 10 | 10 ][---          (size * 8)           ---]
+ ^  ^  ^    ^    ^- size                   ^- file name
  |  |  |    '------ id
  |  |  '----------- file type
  |  '-------------- type1 (0x0)
@@ -470,8 +470,8 @@ Layout of the inline-struct tag:
 ```
         tag                          data
 [--      32      --][---        variable length        ---]
-[1|- 11 -| 10 | 10 ][---            (size)             ---]
- ^    ^     ^    ^- size               ^- inline data
+[1|- 11 -| 10 | 10 ][---           (size * 8)          ---]
+ ^    ^     ^    ^- size                    ^- inline data
  |    |     '------ id
  |    '------------ type (0x201)
  '----------------- valid bit
@@ -556,8 +556,8 @@ Layout of the user-attr tag:
 ```
         tag                          data
 [--      32      --][---        variable length        ---]
-[1| 3| 8 | 10 | 10 ][---            (size)             ---]
- ^  ^  ^    ^    ^- size               ^- attr data
+[1| 3| 8 | 10 | 10 ][---           (size * 8)          ---]
+ ^  ^  ^    ^    ^- size                    ^- attr data
  |  |  |    '------ id
  |  |  '----------- attr type
  |  '-------------- type1 (0x3)
@@ -764,9 +764,9 @@ Layout of the CRC tag:
 ```
         tag                                    data
 [--      32      --][--      32      --|---        variable length        ---]
-[1| 3| 8 | 10 | 10 ][--      32      --|---            (size)             ---]
- ^  ^  ^    ^    ^            ^- crc                      ^- padding
- |  |  |    |    '- size (12)
+[1| 3| 8 | 10 | 10 ][--      32      --|---        (size * 8 - 32)        ---]
+ ^  ^  ^    ^    ^            ^- crc                             ^- padding
+ |  |  |    |    '- size
  |  |  |    '------ id (0x3ff)
  |  |  '----------- valid state
  |  '-------------- type1 (0x5)

+ 15 - 0
lfs.c

@@ -71,6 +71,21 @@ static int lfs_bd_read(lfs_t *lfs,
             diff = lfs_min(diff, rcache->off-off);
         }
 
+        if (size >= hint && off % lfs->cfg->read_size == 0 &&
+                size >= lfs->cfg->read_size) {
+            // bypass cache?
+            diff = lfs_aligndown(diff, lfs->cfg->read_size);
+            int err = lfs->cfg->read(lfs->cfg, block, off, data, diff);
+            if (err) {
+                return err;
+            }
+
+            data += diff;
+            off += diff;
+            size -= diff;
+            continue;
+        }
+
         // load to cache, first condition can no longer fail
         LFS_ASSERT(block < lfs->cfg->block_count);
         rcache->block = block;

+ 17 - 13
lfs_util.h

@@ -50,31 +50,35 @@ extern "C"
 
 // Logging functions
 #ifdef LFS_YES_TRACE
-#define LFS_TRACE(fmt, ...) \
-    printf("%s:%d:trace: " fmt "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_TRACE_(fmt, ...) \
+    printf("%s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
 #else
-#define LFS_TRACE(fmt, ...)
+#define LFS_TRACE(...)
 #endif
 
 #ifndef LFS_NO_DEBUG
-#define LFS_DEBUG(fmt, ...) \
-    printf("%s:%d:debug: " fmt "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_DEBUG_(fmt, ...) \
+    printf("%s:%d:debug: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "")
 #else
-#define LFS_DEBUG(fmt, ...)
+#define LFS_DEBUG(...)
 #endif
 
 #ifndef LFS_NO_WARN
-#define LFS_WARN(fmt, ...) \
-    printf("%s:%d:warn: " fmt "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_WARN_(fmt, ...) \
+    printf("%s:%d:warn: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "")
 #else
-#define LFS_WARN(fmt, ...)
+#define LFS_WARN(...)
 #endif
 
 #ifndef LFS_NO_ERROR
-#define LFS_ERROR(fmt, ...) \
-    printf("%s:%d:error: " fmt "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_ERROR_(fmt, ...) \
+    printf("%s:%d:error: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
+#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "")
 #else
-#define LFS_ERROR(fmt, ...)
+#define LFS_ERROR(...)
 #endif
 
 // Runtime assertions
@@ -107,7 +111,7 @@ static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) {
     return lfs_aligndown(a + alignment-1, alignment);
 }
 
-// Find the next smallest power of 2 less than or equal to a
+// Find the smallest power of 2 greater than or equal to a
 static inline uint32_t lfs_npw2(uint32_t a) {
 #if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
     return 32 - __builtin_clz(a-1);