Skip to content

Commit

Permalink
Rearranged compile-time constant checks to live near lfs_init
Browse files Browse the repository at this point in the history
lfs_init handles the checks/asserts of most configuration, moving these
checks near lfs_init attempts to keep all of these checks nearby each
other.

Also updated the comments to avoid somtimes-ambiguous range notation.

And removed negative bounds checks. Negative bounds should be obviously
incorrect, and 0 is _technically_ not illegal for any define (though
admittedly unlikely to be correct).
  • Loading branch information
geky committed Jan 17, 2024
1 parent c531a5e commit 1fefcbb
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@
#include "lfs.h"
#include "lfs_util.h"

// Configuration Sanity Check
#if (LFS_NAME_MAX <= 0) || (LFS_NAME_MAX > 1022)
#error "LFS_NAME_MAX must be in the range (0, 1022]"
#endif

#if (LFS_FILE_MAX <= 0) || (LFS_FILE_MAX > 4294967295)
#error "LFS_FILE_MAX must be in the range (0, 4294967295]"
#endif

#if (LFS_FILE_MAX > 2147483647)
#warning "LFS_FILE_MAX>2147483647; lfs_file_seek, lfs_file_size, and lfs_file_tell will not function properly."
#endif

#if (LFS_ATTR_MAX < 0) || (LFS_ATTR_MAX > 1022)
#error "LFS_ATTR_MAX must be in the range [0, 1022]"
#endif


// some constants used throughout the code
#define LFS_BLOCK_NULL ((lfs_block_t)-1)
Expand Down Expand Up @@ -4123,6 +4106,21 @@ static int lfs_rawremoveattr(lfs_t *lfs, const char *path, uint8_t type) {


/// Filesystem operations ///

// compile time checks, see lfs.h for why these limits exist
#if LFS_NAME_MAX > 1022
#error "Invalid LFS_NAME_MAX, must be <= 1022"
#endif

#if LFS_FILE_MAX > 4294967295
#error "Invalid LFS_FILE_MAX, must be <= 4294967295"
#endif

#if LFS_ATTR_MAX > 1022
#error "Invalid LFS_ATTR_MAX, must be <= 1022"
#endif

// common filesystem initialization
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->cfg = cfg;
lfs->block_count = cfg->block_count; // May be 0
Expand Down

0 comments on commit 1fefcbb

Please sign in to comment.