Skip to content

Commit 65ea6b3

Browse files
committed
Bumped versions, cleaned up some TODOs and missing comments
1 parent 6774276 commit 65ea6b3

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

lfs.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
722722
return 0;
723723
}
724724

725-
// TODO zeros?
726725
static int lfs_dir_get(lfs_t *lfs, const lfs_dir_t *dir,
727726
lfs_off_t off, void *buffer, lfs_size_t size) {
728727
return lfs_bd_read(lfs, dir->pair[0], off, buffer, size);
@@ -1180,8 +1179,6 @@ int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) {
11801179
break;
11811180
}
11821181

1183-
// TODO common info constructor?
1184-
// TODO also used in lfs_stat
11851182
info->type = 0xf & entry.d.type;
11861183
if (entry.d.type == (LFS_STRUCT_CTZ | LFS_TYPE_REG)) {
11871184
info->size = entry.d.u.file.size;
@@ -1707,7 +1704,6 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) {
17071704
return err;
17081705
}
17091706

1710-
// TODO entry read function?
17111707
lfs_entry_t entry = {.off = file->poff};
17121708
err = lfs_dir_get(lfs, &cwd, entry.off, &entry.d, sizeof(entry.d));
17131709
lfs_entry_fromle32(&entry.d);
@@ -1778,7 +1774,6 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file,
17781774
nsize = size;
17791775

17801776
while (nsize > 0) {
1781-
// TODO can this be collapsed?
17821777
// check if we need a new block
17831778
if (!(file->flags & LFS_F_READING) ||
17841779
file->off == lfs->cfg->block_size) {
@@ -1848,12 +1843,9 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
18481843
}
18491844
}
18501845

1851-
// TODO combine with block allocation?
1852-
// TODO need to move out if no longer fits in block also
1853-
// TODO store INLINE_MAX in superblock?
1854-
// TODO what if inline files is > block size (ie 128)
18551846
if ((file->flags & LFS_F_INLINE) &&
18561847
file->pos + nsize >= file->inline_size) {
1848+
// inline file doesn't fit anymore
18571849
file->block = 0xfffffffe;
18581850
file->off = file->pos;
18591851

@@ -1869,9 +1861,6 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
18691861
}
18701862

18711863
while (nsize > 0) {
1872-
// TODO can this be collapsed?
1873-
// TODO can we reduce this now that block 0 is never allocated?
1874-
// TODO actually, how does this behave if inline max == 0?
18751864
// check if we need a new block
18761865
if (!(file->flags & LFS_F_WRITING) ||
18771866
file->off == lfs->cfg->block_size) {
@@ -1969,7 +1958,6 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
19691958
return file->pos;
19701959
}
19711960

1972-
// TODO handle inlining?
19731961
int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
19741962
if ((file->flags & 3) == LFS_O_RDONLY) {
19751963
return LFS_ERR_BADF;

lfs.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
// Software library version
2828
// Major (top-nibble), incremented on backwards incompatible changes
2929
// Minor (bottom-nibble), incremented on feature additions
30-
#define LFS_VERSION 0x00010003
30+
#define LFS_VERSION 0x00010004
3131
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
3232
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
3333

3434
// Version of On-disk data structures
3535
// Major (top-nibble), incremented on backwards incompatible changes
3636
// Minor (bottom-nibble), incremented on feature additions
37-
#define LFS_DISK_VERSION 0x00010001
37+
#define LFS_DISK_VERSION 0x00010002
3838
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
3939
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
4040

@@ -50,17 +50,25 @@ typedef int32_t lfs_soff_t;
5050

5151
typedef uint32_t lfs_block_t;
5252

53-
// Maximum inline file size in bytes
53+
// Maximum inline file size in bytes. Large inline files require a larger
54+
// read and prog cache, but if a file can be inline it does not need its own
55+
// data block. LFS_ATTRS_MAX + LFS_INLINE_MAX must be <= 0xffff. Stored in
56+
// superblock and must be respected by other littlefs drivers.
5457
#ifndef LFS_INLINE_MAX
5558
#define LFS_INLINE_MAX 0x3ff
5659
#endif
5760

58-
// Maximum size of all attributes per file in bytes
61+
// Maximum size of all attributes per file in bytes, may be redefined but a
62+
// a smaller LFS_ATTRS_MAX has no benefit. LFS_ATTRS_MAX + LFS_INLINE_MAX
63+
// must be <= 0xffff. Stored in superblock and must be respected by other
64+
// littlefs drivers.
5965
#ifndef LFS_ATTRS_MAX
6066
#define LFS_ATTRS_MAX 0x3f
6167
#endif
6268

63-
// Max name size in bytes
69+
// Max name size in bytes, may be redefined to reduce the size of the
70+
// info struct. Stored in superblock and must be respected by other
71+
// littlefs drivers.
6472
#ifndef LFS_NAME_MAX
6573
#define LFS_NAME_MAX 0xff
6674
#endif
@@ -191,11 +199,23 @@ struct lfs_config {
191199
// If enabled, only one file may be opened at a time.
192200
void *file_buffer;
193201

194-
// Optional,
202+
// Optional upper limit on inlined files in bytes. Large inline files
203+
// require a larger read and prog cache, but if a file can be inlined it
204+
// does not need its own data block. Must be smaller than the read size
205+
// and prog size. Defaults to min(LFS_INLINE_MAX, read_size) when zero.
206+
// Stored in superblock and must be respected by other littlefs drivers.
195207
lfs_size_t inline_size;
196-
// Optional,
208+
209+
// Optional upper limit on attributes per file in bytes. No downside for
210+
// larger attributes size but must be less than LFS_ATTRS_MAX. Defaults to
211+
// LFS_ATTRS_MAX when zero.Stored in superblock and must be respected by
212+
// other littlefs drivers.
197213
lfs_size_t attrs_size;
198-
// Optional,
214+
215+
// Optional upper limit on length of file names in bytes. No downside for
216+
// larger names except the size of the info struct which is controlled by
217+
// the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX when zero. Stored in
218+
// superblock and must be respected by other littlefs drivers.
199219
lfs_size_t name_size;
200220
};
201221

0 commit comments

Comments
 (0)