Compare commits

..

1 Commits

Author SHA1 Message Date
Christopher Haster
b1c15c1768 Fixed script issue with bash expansion inside makefile parameter
This was causing code sizes to be reported with several of the logging
functions still built in. A useful number, but not the minimum
achievable code size.
2018-07-10 10:43:58 -05:00
5 changed files with 27 additions and 91 deletions

View File

@@ -16,7 +16,6 @@
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
#include <inttypes.h>
// Block device emulated on existing filesystem
@@ -86,7 +85,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
memset(data, 0, size);
// Read data
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
FILE *f = fopen(emu->path, "rb");
if (!f && errno != ENOENT) {
@@ -125,7 +124,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
assert(block < cfg->block_count);
// Program data
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
FILE *f = fopen(emu->path, "r+b");
if (!f) {
@@ -172,7 +171,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) {
assert(block < cfg->block_count);
// Erase the block
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
struct stat st;
int err = stat(emu->path, &st);
if (err && errno != ENOENT) {
@@ -240,3 +239,4 @@ int lfs_emubd_sync(const struct lfs_config *cfg) {
return 0;
}

View File

@@ -10,11 +10,6 @@
#include "lfs.h"
#include "lfs_util.h"
#ifdef __cplusplus
extern "C"
{
#endif
// Config options
#ifndef LFS_EMUBD_READ_SIZE
@@ -80,8 +75,4 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
int lfs_emubd_sync(const struct lfs_config *cfg);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

49
lfs.c
View File

@@ -7,8 +7,6 @@
#include "lfs.h"
#include "lfs_util.h"
#include <inttypes.h>
/// Caching block device operations ///
static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache,
@@ -310,8 +308,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
// check if we have looked at all blocks since last ack
if (lfs->free.ack == 0) {
LFS_WARN("No more free space %" PRIu32,
lfs->free.i + lfs->free.off);
LFS_WARN("No more free space %d", lfs->free.i + lfs->free.off);
return LFS_ERR_NOSPC;
}
@@ -481,8 +478,7 @@ static int lfs_dir_fetch(lfs_t *lfs,
}
if (!valid) {
LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32 ,
tpair[0], tpair[1]);
LFS_ERROR("Corrupted dir pair at %d %d", tpair[0], tpair[1]);
return LFS_ERR_CORRUPT;
}
@@ -605,7 +601,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
break;
relocate:
//commit was corrupted
LFS_DEBUG("Bad block at %" PRIu32, dir->pair[0]);
LFS_DEBUG("Bad block at %d", dir->pair[0]);
// drop caches and prepare to relocate block
relocated = true;
@@ -613,8 +609,7 @@ relocate:
// can't relocate superblock, filesystem is now frozen
if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
LFS_WARN("Superblock %" PRIu32 " has become unwritable",
oldpair[0]);
LFS_WARN("Superblock %d has become unwritable", oldpair[0]);
return LFS_ERR_CORRUPT;
}
@@ -627,7 +622,7 @@ relocate:
if (relocated) {
// update references if we relocated
LFS_DEBUG("Relocating %" PRIu32 " %" PRIu32 " to %" PRIu32 " %" PRIu32,
LFS_DEBUG("Relocating %d %d to %d %d",
oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]);
int err = lfs_relocate(lfs, oldpair, dir->pair);
if (err) {
@@ -1232,7 +1227,7 @@ static int lfs_ctz_extend(lfs_t *lfs,
}
relocate:
LFS_DEBUG("Bad block at %" PRIu32, nblock);
LFS_DEBUG("Bad block at %d", nblock);
// just clear cache and try a new block
lfs_cache_drop(lfs, &lfs->pcache);
@@ -1282,9 +1277,8 @@ static int lfs_ctz_traverse(lfs_t *lfs,
/// Top level file operations ///
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags,
const struct lfs_file_config *cfg) {
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags) {
// deorphan if we haven't yet, needed at most once after poweron
if ((flags & 3) != LFS_O_RDONLY && !lfs->deorphaned) {
int err = lfs_deorphan(lfs);
@@ -1324,7 +1318,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
}
// setup file struct
file->cfg = cfg;
file->pair[0] = cwd.pair[0];
file->pair[1] = cwd.pair[1];
file->poff = entry.off;
@@ -1342,10 +1335,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
}
// allocate buffer if needed
file->cache.block = 0xffffffff;
if (file->cfg && file->cfg->buffer) {
file->cache.buffer = file->cfg->buffer;
} else if (lfs->cfg->file_buffer) {
if (lfs->cfg->file_buffer) {
if (lfs->files) {
// already in use
return LFS_ERR_NOMEM;
@@ -1373,11 +1363,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
return 0;
}
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags) {
return lfs_file_opencfg(lfs, file, path, flags, NULL);
}
int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
int err = lfs_file_sync(lfs, file);
@@ -1390,7 +1375,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
}
// clean up memory
if (!(file->cfg && file->cfg->buffer) && !lfs->cfg->file_buffer) {
if (!lfs->cfg->file_buffer) {
lfs_free(file->cache.buffer);
}
@@ -1399,7 +1384,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
relocate:
LFS_DEBUG("Bad block at %" PRIu32, file->block);
LFS_DEBUG("Bad block at %d", file->block);
// just relocate what exists into new block
lfs_block_t nblock;
@@ -2410,8 +2395,7 @@ static int lfs_relocate(lfs_t *lfs,
// update internal root
if (lfs_paircmp(oldpair, lfs->root) == 0) {
LFS_DEBUG("Relocating root %" PRIu32 " %" PRIu32,
newpair[0], newpair[1]);
LFS_DEBUG("Relocating root %d %d", newpair[0], newpair[1]);
lfs->root[0] = newpair[0];
lfs->root[1] = newpair[1];
}
@@ -2467,7 +2451,7 @@ int lfs_deorphan(lfs_t *lfs) {
if (!res) {
// we are an orphan
LFS_DEBUG("Found orphan %" PRIu32 " %" PRIu32,
LFS_DEBUG("Found orphan %d %d",
pdir.d.tail[0], pdir.d.tail[1]);
pdir.d.tail[0] = cwd.d.tail[0];
@@ -2483,7 +2467,7 @@ int lfs_deorphan(lfs_t *lfs) {
if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) {
// we have desynced
LFS_DEBUG("Found desync %" PRIu32 " %" PRIu32,
LFS_DEBUG("Found desync %d %d",
entry.d.u.dir[0], entry.d.u.dir[1]);
pdir.d.tail[0] = entry.d.u.dir[0];
@@ -2518,14 +2502,14 @@ int lfs_deorphan(lfs_t *lfs) {
}
if (moved) {
LFS_DEBUG("Found move %" PRIu32 " %" PRIu32,
LFS_DEBUG("Found move %d %d",
entry.d.u.dir[0], entry.d.u.dir[1]);
err = lfs_dir_remove(lfs, &cwd, &entry);
if (err) {
return err;
}
} else {
LFS_DEBUG("Found partial move %" PRIu32 " %" PRIu32,
LFS_DEBUG("Found partial move %d %d",
entry.d.u.dir[0], entry.d.u.dir[1]);
entry.d.type &= ~0x80;
err = lfs_dir_update(lfs, &cwd, &entry, NULL);
@@ -2541,3 +2525,4 @@ int lfs_deorphan(lfs_t *lfs) {
return 0;
}

43
lfs.h
View File

@@ -10,18 +10,13 @@
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
/// Version info ///
// Software library version
// Major (top-nibble), incremented on backwards incompatible changes
// Minor (bottom-nibble), incremented on feature additions
#define LFS_VERSION 0x00010005
#define LFS_VERSION 0x00010004
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
@@ -167,12 +162,6 @@ struct lfs_config {
void *file_buffer;
};
// Optional configuration provided during lfs_file_opencfg
struct lfs_file_config {
// Optional, statically allocated buffer for files. Must be program sized.
// If NULL, malloc will be used by default.
void *buffer;
};
// File info structure
struct lfs_info {
@@ -220,7 +209,6 @@ typedef struct lfs_file {
lfs_block_t head;
lfs_size_t size;
const struct lfs_file_config *cfg;
uint32_t flags;
lfs_off_t pos;
lfs_block_t block;
@@ -288,8 +276,7 @@ typedef struct lfs {
// Format a block device with the littlefs
//
// Requires a littlefs object and config struct. This clobbers the littlefs
// object, and does not leave the filesystem mounted. The config struct must
// be zeroed for defaults and backwards compatibility.
// object, and does not leave the filesystem mounted.
//
// Returns a negative error code on failure.
int lfs_format(lfs_t *lfs, const struct lfs_config *config);
@@ -298,8 +285,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *config);
//
// Requires a littlefs object and config struct. Multiple filesystems
// may be mounted simultaneously with multiple littlefs objects. Both
// lfs and config must be allocated while mounted. The config struct must
// be zeroed for defaults and backwards compatibility.
// lfs and config must be allocated while mounted.
//
// Returns a negative error code on failure.
int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
@@ -337,27 +323,14 @@ int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
// Open a file
//
// The mode that the file is opened in is determined by the flags, which
// are values from the enum lfs_open_flags that are bitwise-ored together.
// The mode that the file is opened in is determined
// by the flags, which are values from the enum lfs_open_flags
// that are bitwise-ored together.
//
// Returns a negative error code on failure.
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags);
// Open a file with extra configuration
//
// The mode that the file is opened in is determined by the flags, which
// are values from the enum lfs_open_flags that are bitwise-ored together.
//
// The config struct provides additional config options per file as described
// above. The config struct must be allocated while the file is open, and the
// config struct must be zeroed for defaults and backwards compatibility.
//
// Returns a negative error code on failure.
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
const char *path, int flags,
const struct lfs_file_config *config);
// Close a file
//
// Any pending writes are written out to storage as though
@@ -487,8 +460,4 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
int lfs_deorphan(lfs_t *lfs);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@@ -34,11 +34,6 @@
#include <stdio.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
// Macros, may be replaced by system specific wrappers. Arguments to these
// macros must not have side-effects as the macros can be removed for a smaller
@@ -178,9 +173,5 @@ static inline void lfs_free(void *p) {
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
#endif