Skip to content

Commit dbcbe4e

Browse files
committed
Changed name of upper-limits from blah_size to blah_max
This standardizes the naming between the LFS_BLAH_MAX macros and the blah_max configuration in the lfs_config structure.
1 parent 213530c commit dbcbe4e

File tree

3 files changed

+56
-58
lines changed

3 files changed

+56
-58
lines changed

lfs.c

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ static int lfs_dir_getinfo(lfs_t *lfs, lfs_mdir_t *dir,
13821382
}
13831383

13841384
int32_t tag = lfs_dir_get(lfs, dir, 0x7c3ff000,
1385-
LFS_MKTAG(LFS_TYPE_NAME, id, lfs->name_size+1), info->name);
1385+
LFS_MKTAG(LFS_TYPE_NAME, id, lfs->name_max+1), info->name);
13861386
if (tag < 0) {
13871387
return tag;
13881388
}
@@ -1422,7 +1422,7 @@ int lfs_mkdir(lfs_t *lfs, const char *path) {
14221422

14231423
// check that name fits
14241424
lfs_size_t nlen = strlen(path);
1425-
if (nlen > lfs->name_size) {
1425+
if (nlen > lfs->name_max) {
14261426
return LFS_ERR_NAMETOOLONG;
14271427
}
14281428

@@ -1842,7 +1842,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
18421842

18431843
// check that name fits
18441844
lfs_size_t nlen = strlen(path);
1845-
if (nlen > lfs->name_size) {
1845+
if (nlen > lfs->name_max) {
18461846
err = LFS_ERR_NAMETOOLONG;
18471847
goto cleanup;
18481848
}
@@ -1892,7 +1892,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
18921892
}
18931893

18941894
if ((file->flags & 3) != LFS_O_RDONLY) {
1895-
if (a->size > lfs->attr_size) {
1895+
if (a->size > lfs->attr_max) {
18961896
err = LFS_ERR_NOSPC;
18971897
goto cleanup;
18981898
}
@@ -2252,7 +2252,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
22522252
}
22532253

22542254
if ((file->flags & LFS_F_INLINE) &&
2255-
file->pos + nsize >= lfs->inline_size) {
2255+
file->pos + nsize >= lfs->inline_max) {
22562256
// inline file doesn't fit anymore
22572257
file->block = 0xfffffffe;
22582258
file->off = file->pos;
@@ -2586,7 +2586,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
25862586
} else {
25872587
// check that name fits
25882588
lfs_size_t nlen = strlen(newpath);
2589-
if (nlen > lfs->name_size) {
2589+
if (nlen > lfs->name_max) {
25902590
return LFS_ERR_NAMETOOLONG;
25912591
}
25922592

@@ -2650,7 +2650,7 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
26502650

26512651
res = lfs_dir_get(lfs, &cwd, 0x7ffff000,
26522652
LFS_MKTAG(0x100 | type, lfs_tagid(res),
2653-
lfs_min(size, lfs->attr_size)), buffer);
2653+
lfs_min(size, lfs->attr_max)), buffer);
26542654
if (res < 0 && res != LFS_ERR_NOENT) {
26552655
return res;
26562656
}
@@ -2660,7 +2660,7 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
26602660

26612661
int lfs_setattr(lfs_t *lfs, const char *path,
26622662
uint8_t type, const void *buffer, lfs_size_t size) {
2663-
if (size > lfs->attr_size) {
2663+
if (size > lfs->attr_max) {
26642664
return LFS_ERR_NOSPC;
26652665
}
26662666

@@ -2681,18 +2681,18 @@ static inline void lfs_superblockfromle32(lfs_superblock_t *superblock) {
26812681
superblock->version = lfs_fromle32(superblock->version);
26822682
superblock->block_size = lfs_fromle32(superblock->block_size);
26832683
superblock->block_count = lfs_fromle32(superblock->block_count);
2684-
superblock->inline_size = lfs_fromle32(superblock->inline_size);
2685-
superblock->attr_size = lfs_fromle32(superblock->attr_size);
2686-
superblock->name_size = lfs_fromle32(superblock->name_size);
2684+
superblock->inline_max = lfs_fromle32(superblock->inline_max);
2685+
superblock->attr_max = lfs_fromle32(superblock->attr_max);
2686+
superblock->name_max = lfs_fromle32(superblock->name_max);
26872687
}
26882688

26892689
static inline void lfs_superblocktole32(lfs_superblock_t *superblock) {
26902690
superblock->version = lfs_tole32(superblock->version);
26912691
superblock->block_size = lfs_tole32(superblock->block_size);
26922692
superblock->block_count = lfs_tole32(superblock->block_count);
2693-
superblock->inline_size = lfs_tole32(superblock->inline_size);
2694-
superblock->attr_size = lfs_tole32(superblock->attr_size);
2695-
superblock->name_size = lfs_tole32(superblock->name_size);
2693+
superblock->inline_max = lfs_tole32(superblock->inline_max);
2694+
superblock->attr_max = lfs_tole32(superblock->attr_max);
2695+
superblock->name_max = lfs_tole32(superblock->name_max);
26962696
}
26972697

26982698
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
@@ -2743,23 +2743,23 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
27432743
}
27442744

27452745
// check that the size limits are sane
2746-
LFS_ASSERT(lfs->cfg->inline_size <= LFS_INLINE_MAX);
2747-
LFS_ASSERT(lfs->cfg->inline_size <= lfs->cfg->cache_size);
2748-
lfs->inline_size = lfs->cfg->inline_size;
2749-
if (!lfs->inline_size) {
2750-
lfs->inline_size = lfs_min(LFS_INLINE_MAX, lfs->cfg->cache_size);
2746+
LFS_ASSERT(lfs->cfg->inline_max <= LFS_INLINE_MAX);
2747+
LFS_ASSERT(lfs->cfg->inline_max <= lfs->cfg->cache_size);
2748+
lfs->inline_max = lfs->cfg->inline_max;
2749+
if (!lfs->inline_max) {
2750+
lfs->inline_max = lfs_min(LFS_INLINE_MAX, lfs->cfg->cache_size);
27512751
}
27522752

2753-
LFS_ASSERT(lfs->cfg->attr_size <= LFS_ATTR_MAX);
2754-
lfs->attr_size = lfs->cfg->attr_size;
2755-
if (!lfs->attr_size) {
2756-
lfs->attr_size = LFS_ATTR_MAX;
2753+
LFS_ASSERT(lfs->cfg->attr_max <= LFS_ATTR_MAX);
2754+
lfs->attr_max = lfs->cfg->attr_max;
2755+
if (!lfs->attr_max) {
2756+
lfs->attr_max = LFS_ATTR_MAX;
27572757
}
27582758

2759-
LFS_ASSERT(lfs->cfg->name_size <= LFS_NAME_MAX);
2760-
lfs->name_size = lfs->cfg->name_size;
2761-
if (!lfs->name_size) {
2762-
lfs->name_size = LFS_NAME_MAX;
2759+
LFS_ASSERT(lfs->cfg->name_max <= LFS_NAME_MAX);
2760+
lfs->name_max = lfs->cfg->name_max;
2761+
if (!lfs->name_max) {
2762+
lfs->name_max = LFS_NAME_MAX;
27632763
}
27642764

27652765
// setup default state
@@ -2836,9 +2836,9 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
28362836

28372837
.block_size = lfs->cfg->block_size,
28382838
.block_count = lfs->cfg->block_count,
2839-
.attr_size = lfs->attr_size,
2840-
.name_size = lfs->name_size,
2841-
.inline_size = lfs->inline_size,
2839+
.attr_max = lfs->attr_max,
2840+
.name_max = lfs->name_max,
2841+
.inline_max = lfs->inline_max,
28422842
};
28432843

28442844
lfs_superblocktole32(&superblock);
@@ -2912,34 +2912,34 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
29122912
lfs_pairfromle32(lfs->root);
29132913

29142914
// check superblock configuration
2915-
if (superblock.attr_size) {
2916-
if (superblock.attr_size > lfs->attr_size) {
2917-
LFS_ERROR("Unsupported attr size (%d > %d)",
2918-
superblock.attr_size, lfs->attr_size);
2915+
if (superblock.attr_max) {
2916+
if (superblock.attr_max > lfs->attr_max) {
2917+
LFS_ERROR("Unsupported attr_max (%d > %d)",
2918+
superblock.attr_max, lfs->attr_max);
29192919
return LFS_ERR_INVAL;
29202920
}
29212921

2922-
lfs->attr_size = superblock.attr_size;
2922+
lfs->attr_max = superblock.attr_max;
29232923
}
29242924

2925-
if (superblock.name_size) {
2926-
if (superblock.name_size > lfs->name_size) {
2927-
LFS_ERROR("Unsupported name size (%d > %d)",
2928-
superblock.name_size, lfs->name_size);
2925+
if (superblock.name_max) {
2926+
if (superblock.name_max > lfs->name_max) {
2927+
LFS_ERROR("Unsupported name_max (%d > %d)",
2928+
superblock.name_max, lfs->name_max);
29292929
return LFS_ERR_INVAL;
29302930
}
29312931

2932-
lfs->name_size = superblock.name_size;
2932+
lfs->name_max = superblock.name_max;
29332933
}
29342934

2935-
if (superblock.inline_size) {
2936-
if (superblock.inline_size > lfs->inline_size) {
2937-
LFS_ERROR("Unsupported inline size (%d > %d)",
2938-
superblock.inline_size, lfs->inline_size);
2935+
if (superblock.inline_max) {
2936+
if (superblock.inline_max > lfs->inline_max) {
2937+
LFS_ERROR("Unsupported inline_max (%d > %d)",
2938+
superblock.inline_max, lfs->inline_max);
29392939
return LFS_ERR_INVAL;
29402940
}
29412941

2942-
lfs->inline_size = superblock.inline_size;
2942+
lfs->inline_max = superblock.inline_max;
29432943
}
29442944

29452945
// scan for any global updates
@@ -3265,7 +3265,7 @@ lfs_ssize_t lfs_fs_getattr(lfs_t *lfs,
32653265

32663266
int32_t res = lfs_dir_get(lfs, &superdir, 0x7ffff000,
32673267
LFS_MKTAG(0x100 | type, 0,
3268-
lfs_min(size, lfs->attr_size)), buffer);
3268+
lfs_min(size, lfs->attr_max)), buffer);
32693269
if (res < 0) {
32703270
return res;
32713271
}
@@ -3275,7 +3275,7 @@ lfs_ssize_t lfs_fs_getattr(lfs_t *lfs,
32753275

32763276
int lfs_fs_setattr(lfs_t *lfs,
32773277
uint8_t type, const void *buffer, lfs_size_t size) {
3278-
if (size > lfs->attr_size) {
3278+
if (size > lfs->attr_max) {
32793279
return LFS_ERR_NOSPC;
32803280
}
32813281

lfs.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,20 @@ struct lfs_config {
217217
// attributes size but must be less than LFS_ATTR_MAX. Defaults to
218218
// LFS_ATTR_MAX when zero.Stored in superblock and must be respected by
219219
// other littlefs drivers.
220-
lfs_size_t attr_size;
220+
lfs_size_t attr_max;
221221

222222
// Optional upper limit on length of file names in bytes. No downside for
223223
// larger names except the size of the info struct which is controlled by
224224
// the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX when zero. Stored in
225225
// superblock and must be respected by other littlefs drivers.
226-
lfs_size_t name_size;
226+
lfs_size_t name_max;
227227

228228
// Optional upper limit on inlined files in bytes. Large inline files
229229
// require a larger cache size, but if a file can be inlined it does not
230230
// need its own data block. Must be smaller than cache_size and less than
231231
// LFS_INLINE_MAX. Defaults to min(LFS_INLINE_MAX, read_size) when zero.
232232
// Stored in superblock and must be respected by other littlefs drivers.
233-
lfs_size_t inline_size;
233+
lfs_size_t inline_max;
234234
};
235235

236236
// File info structure
@@ -361,9 +361,9 @@ typedef struct lfs_superblock {
361361
lfs_size_t block_size;
362362
lfs_size_t block_count;
363363

364-
lfs_size_t attr_size;
365-
lfs_size_t name_size;
366-
lfs_size_t inline_size;
364+
lfs_size_t attr_max;
365+
lfs_size_t name_max;
366+
lfs_size_t inline_max;
367367
} lfs_superblock_t;
368368

369369
typedef struct lfs_free {
@@ -389,9 +389,9 @@ typedef struct lfs {
389389
const struct lfs_config *cfg;
390390
lfs_size_t block_size;
391391
lfs_size_t block_count;
392-
lfs_size_t attr_size;
393-
lfs_size_t name_size;
394-
lfs_size_t inline_size;
392+
lfs_size_t attr_max;
393+
lfs_size_t name_max;
394+
lfs_size_t inline_max;
395395
} lfs_t;
396396

397397

tests/template.fmt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ const struct lfs_config cfg = {{
9292
.erase = &lfs_emubd_erase,
9393
.sync = &lfs_emubd_sync,
9494

95-
.name_size = 255,
96-
9795
.read_size = LFS_READ_SIZE,
9896
.prog_size = LFS_PROG_SIZE,
9997
.cache_size = LFS_CACHE_SIZE,

0 commit comments

Comments
 (0)