Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "lfs_util.h"



Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated white space change.

// some constants used throughout the code
#define LFS_BLOCK_NULL ((lfs_block_t)-1)
#define LFS_BLOCK_INLINE ((lfs_block_t)-2)
Expand Down Expand Up @@ -1769,9 +1770,9 @@ static int lfs_dir_commitcrc(lfs_t *lfs, struct lfs_commit *commit) {
// the caching layer
if (noff >= end || noff >= lfs->pcache.off + lfs->cfg->cache_size) {
// flush buffers
int err = lfs_bd_sync(lfs, &lfs->pcache, &lfs->rcache, false);
if (err) {
return err;
int sync_err = lfs_bd_sync(lfs, &lfs->pcache, &lfs->rcache, false);
if (sync_err) {
return sync_err;
}
}
}
Expand Down Expand Up @@ -4722,16 +4723,16 @@ int lfs_fs_traverse_(lfs_t *lfs,
}

for (int i = 0; i < 2; i++) {
int err = cb(data, dir.tail[i]);
if (err) {
return err;
int traverse_err = cb(data, dir.tail[i]);
if (traverse_err) {
return traverse_err;
}
}

// iterate through ids in directory
int err = lfs_dir_fetch(lfs, &dir, dir.tail);
if (err) {
return err;
int fetch_err = lfs_dir_fetch(lfs, &dir, dir.tail);
if (fetch_err) {
return fetch_err;
}

for (uint16_t id = 0; id < dir.count; id++) {
Expand Down Expand Up @@ -4772,18 +4773,18 @@ int lfs_fs_traverse_(lfs_t *lfs,
}

if ((f->flags & LFS_F_DIRTY) && !(f->flags & LFS_F_INLINE)) {
int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
f->ctz.head, f->ctz.size, cb, data);
if (err) {
if (err_traverse ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces white space/formatting change.

Suggested change
if (err_traverse ) {
if (err_traverse) {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces white space/formatting change.

Suggested change
if (err_traverse ) {
if (err_traverse) {

return err;
}
}

if ((f->flags & LFS_F_WRITING) && !(f->flags & LFS_F_INLINE)) {
int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces white space/formatting change.

Suggested change
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces white space/formatting change.

Suggested change
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,
int err_traverse = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache,

f->block, f->pos, cb, data);
if (err) {
return err;
if (err_traverse ) {
return err_traverse ;
Comment on lines +4786 to +4787
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduces white space/formatting change.

Suggested change
if (err_traverse ) {
return err_traverse ;
if (err_traverse) {
return err_traverse;

}
}
}
Expand All @@ -4803,10 +4804,10 @@ static int lfs_fs_pred(lfs_t *lfs,
.i = 1,
.period = 1,
};
int err = LFS_ERR_OK;
int err1 = LFS_ERR_OK;
while (!lfs_pair_isnull(pdir->tail)) {
err = lfs_tortoise_detectcycles(pdir, &tortoise);
if (err < 0) {
err1 = lfs_tortoise_detectcycles(pdir, &tortoise);
if (err1 < 0) {
Comment on lines +4809 to +4810
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlining this check would eliminate the need for err1 entirely AFAICS.

Suggested change
err1 = lfs_tortoise_detectcycles(pdir, &tortoise);
if (err1 < 0) {
if (lfs_tortoise_detectcycles(pdir, &tortoise) < 0) {

return LFS_ERR_CORRUPT;
}

Expand Down Expand Up @@ -4863,11 +4864,11 @@ static lfs_stag_t lfs_fs_parent(lfs_t *lfs, const lfs_block_t pair[2],
.i = 1,
.period = 1,
};
int err = LFS_ERR_OK;
int err2 = LFS_ERR_OK;
while (!lfs_pair_isnull(parent->tail)) {
err = lfs_tortoise_detectcycles(parent, &tortoise);
if (err < 0) {
return err;
err2 = lfs_tortoise_detectcycles(parent, &tortoise);
if (err2 < 0) {
return err2;
}

lfs_stag_t tag = lfs_dir_fetchmatch(lfs, parent, parent->tail,
Expand Down
7 changes: 7 additions & 0 deletions test_main.c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated new test, that doesn't actually test anything in LittleFS.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// test_main.c
#include <stdio.h>

int main(void) {
printf("Test program started.\n");
return 0;
}
Loading