Cleaned up lfs_t struct

- Removed no longer used fields.
- Commented out related field asserts in lfs_init.
- Commented out pre-lfsr structs and function decls.
- Moved cfg to the first field in lfs_t.

Note that most of the code saves actually came from that last point.
Moving lfs.cfg, probably the currently most accessed field, resulted in
a surprising amount of code savings:

                     code          stack          lfs_t
  before:           33702           2640            220
  after+cfg last:   33592 (-0.3%)   2632 (-0.3%)    164 (-25.5%)
  after+cfg first:  33358 (-1.0%)   2632 (-0.3%)    164 (-25.5%)

Maybe we should take a more rigorous/analytical approach to field
placement?
This commit is contained in:
Christopher Haster
2024-05-15 01:30:40 -05:00
parent 5c70013c11
commit 7980d0e21f
2 changed files with 180 additions and 214 deletions
+28 -41
View File
@@ -7461,10 +7461,8 @@ typedef struct lfsr_traversal {
// we really don't want to pay the RAM cost for a full file, // we really don't want to pay the RAM cost for a full file,
// so only store the relevant bits, is this a hack? yes // so only store the relevant bits, is this a hack? yes
struct { struct {
lfsr_opened_t *next; lfsr_opened_t m;
uint8_t type; const struct lfs_file_config *cfg;
uint16_t flags;
lfsr_mdir_t mdir;
lfsr_bshrub_t bshrub; lfsr_bshrub_t bshrub;
} file; } file;
lfsr_btraversal_t bt; lfsr_btraversal_t bt;
@@ -7521,7 +7519,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// //
case LFSR_TRAVERSAL_MROOTANCHOR:; case LFSR_TRAVERSAL_MROOTANCHOR:;
// fetch the first mroot 0x{0,1} // fetch the first mroot 0x{0,1}
int err = lfsr_mdir_fetch(lfs, &t->file.mdir, int err = lfsr_mdir_fetch(lfs, &t->file.m.mdir,
-1, &LFSR_MPTR_MROOTANCHOR()); -1, &LFSR_MPTR_MROOTANCHOR());
if (err) { if (err) {
return err; return err;
@@ -7532,7 +7530,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
if (tinfo_) { if (tinfo_) {
tinfo_->tag = LFSR_TAG_MDIR; tinfo_->tag = LFSR_TAG_MDIR;
tinfo_->u.mdir = t->file.mdir; tinfo_->u.mdir = t->file.m.mdir;
} }
return 0; return 0;
@@ -7541,14 +7539,14 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// lookup mroot, if we find one this is a fake mroot // lookup mroot, if we find one this is a fake mroot
lfsr_tag_t tag; lfsr_tag_t tag;
lfsr_data_t data; lfsr_data_t data;
err = lfsr_mdir_sublookup(lfs, &t->file.mdir, err = lfsr_mdir_sublookup(lfs, &t->file.m.mdir,
LFSR_TAG_STRUCT, LFSR_TAG_STRUCT,
&tag, &data); &tag, &data);
if (err) { if (err) {
// if we have no mtree/mdir (inlined mdir), we need to traverse // if we have no mtree/mdir (inlined mdir), we need to traverse
// any files in our mroot next // any files in our mroot next
if (err == LFS_ERR_NOENT) { if (err == LFS_ERR_NOENT) {
t->file.mdir.mid = 0; t->file.m.mdir.mid = 0;
t->state = LFSR_TRAVERSAL_MDIR; t->state = LFSR_TRAVERSAL_MDIR;
continue; continue;
} }
@@ -7586,14 +7584,14 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
t->u.mtortoise.step += 1; t->u.mtortoise.step += 1;
// fetch this mroot // fetch this mroot
err = lfsr_mdir_fetch(lfs, &t->file.mdir, -1, &mptr); err = lfsr_mdir_fetch(lfs, &t->file.m.mdir, -1, &mptr);
if (err) { if (err) {
return err; return err;
} }
if (tinfo_) { if (tinfo_) {
tinfo_->tag = LFSR_TAG_MDIR; tinfo_->tag = LFSR_TAG_MDIR;
tinfo_->u.mdir = t->file.mdir; tinfo_->u.mdir = t->file.m.mdir;
} }
return 0; return 0;
@@ -7606,7 +7604,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
return err; return err;
} }
err = lfsr_mdir_fetch(lfs, &t->file.mdir, 0, &mptr); err = lfsr_mdir_fetch(lfs, &t->file.m.mdir, 0, &mptr);
if (err) { if (err) {
return err; return err;
} }
@@ -7616,7 +7614,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
if (tinfo_) { if (tinfo_) {
tinfo_->tag = LFSR_TAG_MDIR; tinfo_->tag = LFSR_TAG_MDIR;
tinfo_->u.mdir = t->file.mdir; tinfo_->u.mdir = t->file.m.mdir;
} }
return 0; return 0;
@@ -7719,7 +7717,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
return err; return err;
} }
err = lfsr_mdir_fetch(lfs, &t->file.mdir, err = lfsr_mdir_fetch(lfs, &t->file.m.mdir,
LFSR_MID(lfs, bid, 0), LFSR_MID(lfs, bid, 0),
&mptr); &mptr);
if (err) { if (err) {
@@ -7731,7 +7729,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
if (tinfo_) { if (tinfo_) {
tinfo_->tag = LFSR_TAG_MDIR; tinfo_->tag = LFSR_TAG_MDIR;
tinfo_->u.mdir = t->file.mdir; tinfo_->u.mdir = t->file.m.mdir;
} }
return 0; return 0;
@@ -7745,14 +7743,14 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// not traversing all blocks? have we exceeded our mdir's weight? // not traversing all blocks? have we exceeded our mdir's weight?
// return to mtree traversal // return to mtree traversal
if (!lfsr_traversal_isall(t) if (!lfsr_traversal_isall(t)
|| lfsr_mid_rid(lfs, t->file.mdir.mid) || lfsr_mid_rid(lfs, t->file.m.mdir.mid)
>= (lfsr_srid_t)t->file.mdir.rbyd.weight) { >= (lfsr_srid_t)t->file.m.mdir.rbyd.weight) {
t->state = LFSR_TRAVERSAL_MTREE; t->state = LFSR_TRAVERSAL_MTREE;
continue; continue;
} }
// do we have a block/btree? // do we have a block/btree?
err = lfsr_mdir_lookupnext(lfs, &t->file.mdir, LFSR_TAG_DATA, err = lfsr_mdir_lookupnext(lfs, &t->file.m.mdir, LFSR_TAG_DATA,
&tag, &data); &tag, &data);
if (err && err != LFS_ERR_NOENT) { if (err && err != LFS_ERR_NOENT) {
return err; return err;
@@ -7767,7 +7765,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// found a bshrub (inlined btree)? // found a bshrub (inlined btree)?
} else if (err != LFS_ERR_NOENT && tag == LFSR_TAG_BSHRUB) { } else if (err != LFS_ERR_NOENT && tag == LFSR_TAG_BSHRUB) {
err = lfsr_data_readshrub(lfs, &data, &t->file.mdir, err = lfsr_data_readshrub(lfs, &data, &t->file.m.mdir,
&t->file.bshrub.u.bshrub); &t->file.bshrub.u.bshrub);
if (err) { if (err) {
return err; return err;
@@ -7783,7 +7781,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// no? continue to next file // no? continue to next file
} else { } else {
t->file.mdir.mid += 1; t->file.m.mdir.mid += 1;
continue; continue;
} }
@@ -7808,7 +7806,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
// start traversing the file // start traversing the file
const lfsr_file_t *file = (const lfsr_file_t*)t->u.o; const lfsr_file_t *file = (const lfsr_file_t*)t->u.o;
t->file.mdir = file->m.mdir; t->file.m.mdir = file->m.mdir;
t->file.bshrub = file->bshrub; t->file.bshrub = file->bshrub;
t->bt = LFSR_BTRAVERSAL(); t->bt = LFSR_BTRAVERSAL();
t->state = LFSR_TRAVERSAL_OPENEDBTREE; t->state = LFSR_TRAVERSAL_OPENEDBTREE;
@@ -7826,7 +7824,7 @@ static int lfsr_traversal_read(lfs_t *lfs, lfsr_traversal_t *t,
if (err == LFS_ERR_NOENT) { if (err == LFS_ERR_NOENT) {
// end of btree? go to next file // end of btree? go to next file
if (t->state == LFSR_TRAVERSAL_MDIRBTREE) { if (t->state == LFSR_TRAVERSAL_MDIRBTREE) {
t->file.mdir.mid += 1; t->file.m.mdir.mid += 1;
t->state = LFSR_TRAVERSAL_MDIR; t->state = LFSR_TRAVERSAL_MDIR;
continue; continue;
} else if (t->state == LFSR_TRAVERSAL_OPENEDBTREE) { } else if (t->state == LFSR_TRAVERSAL_OPENEDBTREE) {
@@ -15304,29 +15302,18 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->file_limit = LFS_FILE_MAX; lfs->file_limit = LFS_FILE_MAX;
} }
LFS_ASSERT(lfs->cfg->uattr_limit <= LFS_UATTR_MAX);
lfs->uattr_limit = lfs->cfg->uattr_limit;
if (!lfs->uattr_limit) {
lfs->uattr_limit = LFS_UATTR_MAX;
}
LFS_ASSERT(lfs->cfg->sattr_limit <= LFS_SATTR_MAX);
lfs->sattr_limit = lfs->cfg->sattr_limit;
if (!lfs->sattr_limit) {
lfs->sattr_limit = LFS_SATTR_MAX;
}
// setup default state // setup default state
lfs->seed = 0;
// lfs->root[0] = LFS_BLOCK_NULL; // lfs->root[0] = LFS_BLOCK_NULL;
// lfs->root[1] = LFS_BLOCK_NULL; // lfs->root[1] = LFS_BLOCK_NULL;
lfs->mlist = NULL; // lfs->mlist = NULL;
lfs->seed = 0; // lfs->gdisk = (lfs_gstate_t){0};
lfs->gdisk = (lfs_gstate_t){0}; // lfs->gstate = (lfs_gstate_t){0};
lfs->gstate = (lfs_gstate_t){0}; // lfs->gdelta = (lfs_gstate_t){0};
lfs->gdelta = (lfs_gstate_t){0}; //#ifdef LFS_MIGRATE
#ifdef LFS_MIGRATE // lfs->lfs1 = NULL;
lfs->lfs1 = NULL; //#endif
#endif
// TODO maybe reorganize this function? // TODO maybe reorganize this function?
+152 -173
View File
@@ -81,15 +81,15 @@ typedef int32_t lfsr_sdid_t;
//#ifndef LFS_ATTR_MAX //#ifndef LFS_ATTR_MAX
//#define LFS_ATTR_MAX 1022 //#define LFS_ATTR_MAX 1022
//#endif //#endif
//
// TODO document //// TODO document
#ifndef LFS_UATTR_MAX //#ifndef LFS_UATTR_MAX
#define LFS_UATTR_MAX 255 //#define LFS_UATTR_MAX 255
#endif //#endif
//
#ifndef LFS_SATTR_MAX //#ifndef LFS_SATTR_MAX
#define LFS_SATTR_MAX 255 //#define LFS_SATTR_MAX 255
#endif //#endif
// Possible error codes, these are negative to allow // Possible error codes, these are negative to allow
@@ -258,10 +258,6 @@ struct lfs_config {
// in superblock and must be respected by other littlefs drivers. // in superblock and must be respected by other littlefs drivers.
lfs_size_t file_limit; lfs_size_t file_limit;
// TODO document
lfs_size_t uattr_limit;
lfs_size_t sattr_limit;
// TODO rm me // TODO rm me
// // Optional upper limit on custom attributes in bytes. No downside for // // Optional upper limit on custom attributes in bytes. No downside for
// // larger attributes size but must be <= LFS_ATTR_MAX. Defaults to // // larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
@@ -320,19 +316,19 @@ struct lfs_info {
char name[LFS_NAME_MAX+1]; char name[LFS_NAME_MAX+1];
}; };
// Custom attribute structure, used to describe custom attributes //// Custom attribute structure, used to describe custom attributes
// committed atomically during file writes. //// committed atomically during file writes.
struct lfs_attr { //struct lfs_attr {
// 8-bit type of attribute, provided by user and used to // // 8-bit type of attribute, provided by user and used to
// identify the attribute // // identify the attribute
uint8_t type; // uint8_t type;
//
// Pointer to buffer containing the attribute // // Pointer to buffer containing the attribute
void *buffer; // void *buffer;
//
// Size of attribute in bytes, limited to LFS_ATTR_MAX // // Size of attribute in bytes, limited to LFS_ATTR_MAX
lfs_size_t size; // lfs_size_t size;
}; //};
// Optional configuration provided during lfs_file_opencfg // Optional configuration provided during lfs_file_opencfg
struct lfs_file_config { struct lfs_file_config {
@@ -345,31 +341,32 @@ struct lfs_file_config {
// accesses. Defaults to file_buffer_size. // accesses. Defaults to file_buffer_size.
lfs_size_t buffer_size; lfs_size_t buffer_size;
// Optional list of custom attributes related to the file. If the file // // Optional list of custom attributes related to the file. If the file
// is opened with read access, these attributes will be read from disk // // is opened with read access, these attributes will be read from disk
// during the open call. If the file is opened with write access, the // // during the open call. If the file is opened with write access, the
// attributes will be written to disk every file sync or close. This // // attributes will be written to disk every file sync or close. This
// write occurs atomically with update to the file's contents. // // write occurs atomically with update to the file's contents.
// // //
// Custom attributes are uniquely identified by an 8-bit type and limited // // Custom attributes are uniquely identified by an 8-bit type and limited
// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller // // to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller
// than the buffer, it will be padded with zeros. If the stored attribute // // than the buffer, it will be padded with zeros. If the stored attribute
// is larger, then it will be silently truncated. If the attribute is not // // is larger, then it will be silently truncated. If the attribute is not
// found, it will be created implicitly. // // found, it will be created implicitly.
struct lfs_attr *attrs; // struct lfs_attr *attrs;
//
// Number of custom attributes in the list // // Number of custom attributes in the list
lfs_size_t attr_count; // lfs_size_t attr_count;
}; };
/// internal littlefs data structures /// /// internal littlefs data structures ///
typedef struct lfs_cache {
lfs_block_t block; //typedef struct lfs_cache {
lfs_size_t off; // lfs_block_t block;
lfs_size_t size; // lfs_size_t off;
uint8_t *buffer; // lfs_size_t size;
} lfs_cache_t; // uint8_t *buffer;
//} lfs_cache_t;
// TODO do we get ram savings with a lfsr_rorbyd_t substruct? need to measure // TODO do we get ram savings with a lfsr_rorbyd_t substruct? need to measure
typedef struct lfsr_rbyd { typedef struct lfsr_rbyd {
@@ -418,16 +415,16 @@ typedef struct lfsr_opened {
} lfsr_opened_t; } lfsr_opened_t;
typedef struct lfs_mdir { //typedef struct lfs_mdir {
lfs_block_t pair[2]; // lfs_block_t pair[2];
uint32_t rev; // uint32_t rev;
lfs_off_t off; // lfs_off_t off;
uint32_t etag; // uint32_t etag;
uint16_t count; // uint16_t count;
bool erased; // bool erased;
bool split; // bool split;
lfs_block_t tail[2]; // lfs_block_t tail[2];
} lfs_mdir_t; //} lfs_mdir_t;
// either an on-disk or in-device data pointer // either an on-disk or in-device data pointer
typedef struct lfsr_data { typedef struct lfsr_data {
@@ -444,15 +441,16 @@ typedef struct lfsr_data {
} lfsr_data_t; } lfsr_data_t;
// littlefs directory type // littlefs directory type
typedef struct lfs_dir {
struct lfs_dir *next;
uint16_t id;
uint8_t type;
lfs_mdir_t m;
lfs_off_t pos; //typedef struct lfs_dir {
lfs_block_t head[2]; // struct lfs_dir *next;
} lfs_dir_t; // uint16_t id;
// uint8_t type;
// lfs_mdir_t m;
//
// lfs_off_t pos;
// lfs_block_t head[2];
//} lfs_dir_t;
typedef struct lfsr_dir { typedef struct lfsr_dir {
lfsr_opened_t p; // pos mdir lfsr_opened_t p; // pos mdir
@@ -462,25 +460,26 @@ typedef struct lfsr_dir {
} lfsr_dir_t; } lfsr_dir_t;
// littlefs file type // littlefs file type
typedef struct lfs_file {
struct lfs_file *next;
uint16_t id;
uint8_t type;
lfs_mdir_t m;
struct lfs_ctz { //typedef struct lfs_file {
lfs_block_t head; // struct lfs_file *next;
lfs_size_t size; // uint16_t id;
} ctz; // uint8_t type;
// lfs_mdir_t m;
uint32_t flags; //
lfs_off_t pos; // struct lfs_ctz {
lfs_block_t block; // lfs_block_t head;
lfs_off_t off; // lfs_size_t size;
lfs_cache_t cache; // } ctz;
//
const struct lfs_file_config *cfg; // uint32_t flags;
} lfs_file_t; // lfs_off_t pos;
// lfs_block_t block;
// lfs_off_t off;
// lfs_cache_t cache;
//
// const struct lfs_file_config *cfg;
//} lfs_file_t;
typedef lfsr_data_t lfsr_sprout_t; typedef lfsr_data_t lfsr_sprout_t;
@@ -512,6 +511,7 @@ typedef struct lfsr_bshrub {
typedef struct lfsr_file { typedef struct lfsr_file {
lfsr_opened_t m; lfsr_opened_t m;
const struct lfs_file_config *cfg;
// files contain both an active bshrub and staging bshrub, to allow // files contain both an active bshrub and staging bshrub, to allow
// staging during mdir compacts // staging during mdir compacts
@@ -528,23 +528,21 @@ typedef struct lfsr_file {
lfs_block_t eblock; lfs_block_t eblock;
lfs_size_t eoff; lfs_size_t eoff;
const struct lfs_file_config *cfg;
} lfsr_file_t; } lfsr_file_t;
typedef struct lfs_superblock { //typedef struct lfs_superblock {
uint32_t version; // uint32_t version;
lfs_size_t block_size; // lfs_size_t block_size;
lfs_size_t block_count; // lfs_size_t block_count;
lfs_size_t name_max; // lfs_size_t name_max;
lfs_size_t file_max; // lfs_size_t file_max;
lfs_size_t attr_max; // lfs_size_t attr_max;
} lfs_superblock_t; //} lfs_superblock_t;
//
typedef struct lfs_gstate { //typedef struct lfs_gstate {
uint32_t tag; // uint32_t tag;
lfs_block_t pair[2]; // lfs_block_t pair[2];
} lfs_gstate_t; //} lfs_gstate_t;
typedef struct lfsr_mtree { typedef struct lfsr_mtree {
union { union {
@@ -576,6 +574,24 @@ typedef struct lfsr_grm {
// The littlefs filesystem type // The littlefs filesystem type
typedef struct lfs { typedef struct lfs {
const struct lfs_config *cfg;
lfs_size_t name_limit;
lfs_off_t file_limit;
// TODO we should put this flag somewhere, should lfs_t have a general
// purpose flags field? this has been useful for lfsr_file_t
bool hasorphans;
uint8_t attr_estimate;
uint8_t mleaf_bits;
// linked-list of opened mdirs
lfsr_opened_t *opened;
lfsr_mdir_t mroot;
lfsr_mtree_t mtree;
uint32_t seed;
struct { struct {
lfs_block_t block; lfs_block_t block;
lfs_size_t off; lfs_size_t off;
@@ -590,19 +606,6 @@ typedef struct lfs {
} pcache; } pcache;
uint32_t pcksum; uint32_t pcksum;
lfs_block_t root[2];
struct lfs_mlist {
struct lfs_mlist *next;
uint16_t id;
uint8_t type;
lfs_mdir_t m;
} *mlist;
uint32_t seed;
lfs_gstate_t gstate;
lfs_gstate_t gdisk;
lfs_gstate_t gdelta;
struct lfs_lookahead { struct lfs_lookahead {
lfs_block_t start; lfs_block_t start;
lfs_block_t size; lfs_block_t size;
@@ -611,33 +614,9 @@ typedef struct lfs {
uint8_t *buffer; uint8_t *buffer;
} lookahead; } lookahead;
const struct lfs_config *cfg;
lfs_size_t name_limit;
lfs_off_t file_limit;
lfs_size_t uattr_limit;
lfs_size_t sattr_limit;
// begin lfsr things
lfsr_grm_t grm; lfsr_grm_t grm;
uint8_t grm_g[LFSR_GRM_DSIZE]; uint8_t grm_g[LFSR_GRM_DSIZE];
uint8_t grm_d[LFSR_GRM_DSIZE]; uint8_t grm_d[LFSR_GRM_DSIZE];
// TODO we should put this flag somewhere, should lfs_t have a general
// purpose flags field? this has been useful for lfsr_file_t
bool hasorphans;
uint8_t attr_estimate;
uint8_t mleaf_bits;
lfsr_mdir_t mroot;
lfsr_mtree_t mtree;
// linked-list of opened mdirs
lfsr_opened_t *opened;
#ifdef LFS_MIGRATE
struct lfs1 *lfs1;
#endif
} lfs_t; } lfs_t;
@@ -651,7 +630,7 @@ typedef struct lfs {
// be zeroed for defaults and backwards compatibility. // be zeroed for defaults and backwards compatibility.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_format(lfs_t *lfs, const struct lfs_config *config); //int lfs_format(lfs_t *lfs, const struct lfs_config *config);
int lfsr_format(lfs_t *lfs, const struct lfs_config *config); int lfsr_format(lfs_t *lfs, const struct lfs_config *config);
#endif #endif
@@ -663,14 +642,14 @@ int lfsr_format(lfs_t *lfs, const struct lfs_config *config);
// be zeroed for defaults and backwards compatibility. // be zeroed for defaults and backwards compatibility.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_mount(lfs_t *lfs, const struct lfs_config *config); //int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
int lfsr_mount(lfs_t *lfs, const struct lfs_config *config); int lfsr_mount(lfs_t *lfs, const struct lfs_config *config);
// Unmounts a littlefs // Unmounts a littlefs
// //
// Does nothing besides releasing any allocated resources. // Does nothing besides releasing any allocated resources.
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_unmount(lfs_t *lfs); //int lfs_unmount(lfs_t *lfs);
int lfsr_unmount(lfs_t *lfs); int lfsr_unmount(lfs_t *lfs);
/// General operations /// /// General operations ///
@@ -680,7 +659,7 @@ int lfsr_unmount(lfs_t *lfs);
// //
// If removing a directory, the directory must be empty. // If removing a directory, the directory must be empty.
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_remove(lfs_t *lfs, const char *path); //int lfs_remove(lfs_t *lfs, const char *path);
int lfsr_remove(lfs_t *lfs, const char *path); int lfsr_remove(lfs_t *lfs, const char *path);
#endif #endif
@@ -691,7 +670,7 @@ int lfsr_remove(lfs_t *lfs, const char *path);
// If the destination is a directory, the directory must be empty. // If the destination is a directory, the directory must be empty.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath); //int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path); int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path);
#endif #endif
@@ -699,7 +678,7 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path);
// //
// Fills out the info structure, based on the specified file or directory. // Fills out the info structure, based on the specified file or directory.
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info); //int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info); int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
// Get a custom attribute // Get a custom attribute
@@ -714,8 +693,8 @@ int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
// Note, the returned size is the size of the attribute on disk, irrespective // Note, the returned size is the size of the attribute on disk, irrespective
// of the size of the buffer. This can be used to dynamically allocate a buffer // of the size of the buffer. This can be used to dynamically allocate a buffer
// or check for existence. // or check for existence.
lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path, //lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
uint8_t type, void *buffer, lfs_size_t size); // uint8_t type, void *buffer, lfs_size_t size);
#ifndef LFS_READONLY #ifndef LFS_READONLY
// Set custom attributes // Set custom attributes
@@ -725,8 +704,8 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path,
// implicitly created. // implicitly created.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_setattr(lfs_t *lfs, const char *path, //int lfs_setattr(lfs_t *lfs, const char *path,
uint8_t type, const void *buffer, lfs_size_t size); // uint8_t type, const void *buffer, lfs_size_t size);
#endif #endif
#ifndef LFS_READONLY #ifndef LFS_READONLY
@@ -735,7 +714,7 @@ int lfs_setattr(lfs_t *lfs, const char *path,
// If an attribute is not found, nothing happens. // If an attribute is not found, nothing happens.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type); //int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
#endif #endif
@@ -748,8 +727,8 @@ int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type);
// are values from the enum lfs_open_flags that are bitwise-ored together. // are values from the enum lfs_open_flags that are bitwise-ored together.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_open(lfs_t *lfs, lfs_file_t *file, //int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags); // const char *path, int flags);
int lfsr_file_open(lfs_t *lfs, lfsr_file_t *file, int lfsr_file_open(lfs_t *lfs, lfsr_file_t *file,
const char *path, uint32_t flags); const char *path, uint32_t flags);
@@ -767,9 +746,9 @@ int lfsr_file_open(lfs_t *lfs, lfsr_file_t *file,
// the config struct must be zeroed for defaults and backwards compatibility. // the config struct must be zeroed for defaults and backwards compatibility.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, //int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags, // const char *path, int flags,
const struct lfs_file_config *config); // const struct lfs_file_config *config);
int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file, int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
const char *path, uint32_t flags, const char *path, uint32_t flags,
const struct lfs_file_config *config); const struct lfs_file_config *config);
@@ -785,7 +764,7 @@ int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
// return 0. // return 0.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_close(lfs_t *lfs, lfs_file_t *file); //int lfs_file_close(lfs_t *lfs, lfs_file_t *file);
int lfsr_file_close(lfs_t *lfs, lfsr_file_t *file); int lfsr_file_close(lfs_t *lfs, lfsr_file_t *file);
// Synchronize a file on storage // Synchronize a file on storage
@@ -796,7 +775,7 @@ int lfsr_file_close(lfs_t *lfs, lfsr_file_t *file);
// now recieve file updates and syncs on close. // now recieve file updates and syncs on close.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_sync(lfs_t *lfs, lfs_file_t *file); //int lfs_file_sync(lfs_t *lfs, lfs_file_t *file);
int lfsr_file_sync(lfs_t *lfs, lfsr_file_t *file); int lfsr_file_sync(lfs_t *lfs, lfsr_file_t *file);
// Mark a file as desynchronized // Mark a file as desynchronized
@@ -827,8 +806,8 @@ int lfsr_file_flush(lfs_t *lfs, lfsr_file_t *file);
// //
// Takes a buffer and size indicating where to store the read data. // Takes a buffer and size indicating where to store the read data.
// Returns the number of bytes read, or a negative error code on failure. // Returns the number of bytes read, or a negative error code on failure.
lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, //lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file,
void *buffer, lfs_size_t size); // void *buffer, lfs_size_t size);
lfs_ssize_t lfsr_file_read(lfs_t *lfs, lfsr_file_t *file, lfs_ssize_t lfsr_file_read(lfs_t *lfs, lfsr_file_t *file,
void *buffer, lfs_size_t size); void *buffer, lfs_size_t size);
@@ -839,8 +818,8 @@ lfs_ssize_t lfsr_file_read(lfs_t *lfs, lfsr_file_t *file,
// actually be updated on the storage until either sync or close is called. // actually be updated on the storage until either sync or close is called.
// //
// Returns the number of bytes written, or a negative error code on failure. // Returns the number of bytes written, or a negative error code on failure.
lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, //lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
const void *buffer, lfs_size_t size); // const void *buffer, lfs_size_t size);
lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file, lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file,
const void *buffer, lfs_size_t size); const void *buffer, lfs_size_t size);
#endif #endif
@@ -849,8 +828,8 @@ lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file,
// //
// The change in position is determined by the offset and whence flag. // The change in position is determined by the offset and whence flag.
// Returns the new position of the file, or a negative error code on failure. // Returns the new position of the file, or a negative error code on failure.
lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, //lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
lfs_soff_t off, int whence); // lfs_soff_t off, int whence);
lfs_soff_t lfsr_file_seek(lfs_t *lfs, lfsr_file_t *file, lfs_soff_t lfsr_file_seek(lfs_t *lfs, lfsr_file_t *file,
lfs_soff_t off, uint8_t whence); lfs_soff_t off, uint8_t whence);
@@ -861,7 +840,7 @@ lfs_soff_t lfsr_file_seek(lfs_t *lfs, lfsr_file_t *file,
// as if the file was filled with zeros. // as if the file was filled with zeros.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size); //int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size);
int lfsr_file_truncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size); int lfsr_file_truncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size);
#endif #endif
@@ -879,21 +858,21 @@ int lfsr_file_fruncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size);
// //
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR) // Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR)
// Returns the position of the file, or a negative error code on failure. // Returns the position of the file, or a negative error code on failure.
lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file); //lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file);
lfs_soff_t lfsr_file_tell(lfs_t *lfs, lfsr_file_t *file); lfs_soff_t lfsr_file_tell(lfs_t *lfs, lfsr_file_t *file);
// Change the position of the file to the beginning of the file // Change the position of the file to the beginning of the file
// //
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET) // Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET)
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file); //int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
int lfsr_file_rewind(lfs_t *lfs, lfsr_file_t *file); int lfsr_file_rewind(lfs_t *lfs, lfsr_file_t *file);
// Return the size of the file // Return the size of the file
// //
// Similar to lfs_file_seek(lfs, file, 0, LFS_SEEK_END) // Similar to lfs_file_seek(lfs, file, 0, LFS_SEEK_END)
// Returns the size of the file, or a negative error code on failure. // Returns the size of the file, or a negative error code on failure.
lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file); //lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file);
lfs_soff_t lfsr_file_size(lfs_t *lfs, lfsr_file_t *file); lfs_soff_t lfsr_file_size(lfs_t *lfs, lfsr_file_t *file);
@@ -903,7 +882,7 @@ lfs_soff_t lfsr_file_size(lfs_t *lfs, lfsr_file_t *file);
// Create a directory // Create a directory
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_mkdir(lfs_t *lfs, const char *path); //int lfs_mkdir(lfs_t *lfs, const char *path);
int lfsr_mkdir(lfs_t *lfs, const char *path); int lfsr_mkdir(lfs_t *lfs, const char *path);
#endif #endif
@@ -911,14 +890,14 @@ int lfsr_mkdir(lfs_t *lfs, const char *path);
// //
// Once open a directory can be used with read to iterate over files. // Once open a directory can be used with read to iterate over files.
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path); //int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path);
int lfsr_dir_open(lfs_t *lfs, lfsr_dir_t *dir, const char *path); int lfsr_dir_open(lfs_t *lfs, lfsr_dir_t *dir, const char *path);
// Close a directory // Close a directory
// //
// Releases any allocated resources. // Releases any allocated resources.
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir); //int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
int lfsr_dir_close(lfs_t *lfs, lfsr_dir_t *dir); int lfsr_dir_close(lfs_t *lfs, lfsr_dir_t *dir);
// Read an entry in the directory // Read an entry in the directory
@@ -926,7 +905,7 @@ int lfsr_dir_close(lfs_t *lfs, lfsr_dir_t *dir);
// Fills out the info structure, based on the specified file or directory. // Fills out the info structure, based on the specified file or directory.
// Returns a positive value on success, 0 at the end of directory, // Returns a positive value on success, 0 at the end of directory,
// or a negative error code on failure. // or a negative error code on failure.
int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info); //int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info); int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info);
// Change the position of the directory // Change the position of the directory
@@ -935,7 +914,7 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info);
// an absolute offset in the directory seek. // an absolute offset in the directory seek.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off); //int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off);
int lfsr_dir_seek(lfs_t *lfs, lfsr_dir_t *dir, lfs_soff_t off); int lfsr_dir_seek(lfs_t *lfs, lfsr_dir_t *dir, lfs_soff_t off);
// Return the position of the directory // Return the position of the directory
@@ -944,13 +923,13 @@ int lfsr_dir_seek(lfs_t *lfs, lfsr_dir_t *dir, lfs_soff_t off);
// sense, but does indicate the current position in the directory iteration. // sense, but does indicate the current position in the directory iteration.
// //
// Returns the position of the directory, or a negative error code on failure. // Returns the position of the directory, or a negative error code on failure.
lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir); //lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir);
lfs_soff_t lfsr_dir_tell(lfs_t *lfs, lfsr_dir_t *dir); lfs_soff_t lfsr_dir_tell(lfs_t *lfs, lfsr_dir_t *dir);
// Change the position of the directory to the beginning of the directory // Change the position of the directory to the beginning of the directory
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir); //int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);
int lfsr_dir_rewind(lfs_t *lfs, lfsr_dir_t *dir); int lfsr_dir_rewind(lfs_t *lfs, lfsr_dir_t *dir);
@@ -962,7 +941,7 @@ int lfsr_dir_rewind(lfs_t *lfs, lfsr_dir_t *dir);
// size may be larger than the filesystem actually is. // size may be larger than the filesystem actually is.
// //
// Returns the number of allocated blocks, or a negative error code on failure. // Returns the number of allocated blocks, or a negative error code on failure.
lfs_ssize_t lfs_fs_size(lfs_t *lfs); //lfs_ssize_t lfs_fs_size(lfs_t *lfs);
lfs_ssize_t lfsr_fs_size(lfs_t *lfs); lfs_ssize_t lfsr_fs_size(lfs_t *lfs);
// Traverse through all blocks in use by the filesystem // Traverse through all blocks in use by the filesystem
@@ -972,7 +951,7 @@ lfs_ssize_t lfsr_fs_size(lfs_t *lfs);
// blocks are in use or how much of the storage is available. // blocks are in use or how much of the storage is available.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data); //int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
#ifndef LFS_READONLY #ifndef LFS_READONLY
#ifdef LFS_MIGRATE #ifdef LFS_MIGRATE
@@ -987,7 +966,7 @@ int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
// be zeroed for defaults and backwards compatibility. // be zeroed for defaults and backwards compatibility.
// //
// Returns a negative error code on failure. // Returns a negative error code on failure.
int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); //int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg);
#endif #endif
#endif #endif