Expanded inline files up to a limit of 1023 bytes

One of the big benefits of inline files is that small files no longer need to
take up a full block. This opens up an opportunity to provide much better
support for storage devices with only a handful of very large blocks. Such as
the internal flash found on most microcontrollers.

After investigating some use cases for a filesystem on internal flash,
it has become apparent that the 255-byte limit is going to be too
restrictive to be useful in many cases. Most uses I found needed files
~4-64 bytes in size, but it wasn't uncommon to find files ~512 bytes in
length.

To try to remedy this, I've pushed the 255 byte limit up to 1023 bytes,
by stealing some bits from the previously-unused attributes's size.
Unfortunately this limits attributes to 63 bytes in total and has a
minor code cost, but I'm not sure even 1023 bytes will be sufficient for
a lot of cases.

The littlefs will probably never be as efficient with internal flash as
other filesystems such as SPIFFS, it just wasn't designed for this sort of
limited geometry. However, this feature has been heavily requested, even
with limitations, because of the opportunity for code reuse on
microcontrollers with both internal and external flash.
This commit is contained in:
Christopher Haster
2018-04-03 08:28:09 -05:00
parent 6362afa8d0
commit 6774276124
2 changed files with 71 additions and 39 deletions

7
lfs.h
View File

@@ -52,17 +52,17 @@ typedef uint32_t lfs_block_t;
// Maximum inline file size in bytes
#ifndef LFS_INLINE_MAX
#define LFS_INLINE_MAX 255
#define LFS_INLINE_MAX 0x3ff
#endif
// Maximum size of all attributes per file in bytes
#ifndef LFS_ATTRS_MAX
#define LFS_ATTRS_MAX 255
#define LFS_ATTRS_MAX 0x3f
#endif
// Max name size in bytes
#ifndef LFS_NAME_MAX
#define LFS_NAME_MAX 255
#define LFS_NAME_MAX 0xff
#endif
// Possible error codes, these are negative to allow
@@ -248,6 +248,7 @@ typedef struct lfs_file {
lfs_size_t size;
uint32_t flags;
lfs_size_t inline_size;
lfs_off_t pos;
lfs_block_t block;
lfs_off_t off;