Generated v2 prefixes

This commit is contained in:
geky-bot
2023-05-04 18:31:30 +00:00
67 changed files with 26771 additions and 5203 deletions
+30 -87
View File
@@ -15,39 +15,6 @@
#include <windows.h>
#endif
int lfs2_filebd_createcfg(const struct lfs2_config *cfg, const char *path,
const struct lfs2_filebd_config *bdcfg) {
LFS2_FILEBD_TRACE("lfs2_filebd_createcfg(%p {.context=%p, "
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
".block_size=%"PRIu32", .block_count=%"PRIu32"}, "
"\"%s\", "
"%p {.erase_value=%"PRId32"})",
(void*)cfg, cfg->context,
(void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
(void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
path, (void*)bdcfg, bdcfg->erase_value);
lfs2_filebd_t *bd = cfg->context;
bd->cfg = bdcfg;
// open file
#ifdef _WIN32
bd->fd = open(path, O_RDWR | O_CREAT | O_BINARY, 0666);
#else
bd->fd = open(path, O_RDWR | O_CREAT, 0666);
#endif
if (bd->fd < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_createcfg -> %d", err);
return err;
}
LFS2_FILEBD_TRACE("lfs2_filebd_createcfg -> %d", 0);
return 0;
}
int lfs2_filebd_create(const struct lfs2_config *cfg, const char *path) {
LFS2_FILEBD_TRACE("lfs2_filebd_create(%p {.context=%p, "
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
@@ -58,11 +25,24 @@ int lfs2_filebd_create(const struct lfs2_config *cfg, const char *path) {
(void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
(void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
path);
static const struct lfs2_filebd_config defaults = {.erase_value=-1};
int err = lfs2_filebd_createcfg(cfg, path, &defaults);
LFS2_FILEBD_TRACE("lfs2_filebd_create -> %d", err);
return err;
path, (void*)bdcfg, bdcfg->erase_value);
lfs2_filebd_t *bd = cfg->context;
// open file
#ifdef _WIN32
bd->fd = open(path, O_RDWR | O_CREAT | O_BINARY, 0666);
#else
bd->fd = open(path, O_RDWR | O_CREAT, 0666);
#endif
if (bd->fd < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_create -> %d", err);
return err;
}
LFS2_FILEBD_TRACE("lfs2_filebd_create -> %d", 0);
return 0;
}
int lfs2_filebd_destroy(const struct lfs2_config *cfg) {
@@ -86,14 +66,13 @@ int lfs2_filebd_read(const struct lfs2_config *cfg, lfs2_block_t block,
lfs2_filebd_t *bd = cfg->context;
// check if read is valid
LFS2_ASSERT(block < cfg->block_count);
LFS2_ASSERT(off % cfg->read_size == 0);
LFS2_ASSERT(size % cfg->read_size == 0);
LFS2_ASSERT(block < cfg->block_count);
LFS2_ASSERT(off+size <= cfg->block_size);
// zero for reproducibility (in case file is truncated)
if (bd->cfg->erase_value != -1) {
memset(buffer, bd->cfg->erase_value, size);
}
memset(buffer, 0, size);
// read
off_t res1 = lseek(bd->fd,
@@ -117,37 +96,16 @@ int lfs2_filebd_read(const struct lfs2_config *cfg, lfs2_block_t block,
int lfs2_filebd_prog(const struct lfs2_config *cfg, lfs2_block_t block,
lfs2_off_t off, const void *buffer, lfs2_size_t size) {
LFS2_FILEBD_TRACE("lfs2_filebd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")",
LFS2_FILEBD_TRACE("lfs2_filebd_prog(%p, "
"0x%"PRIx32", %"PRIu32", %p, %"PRIu32")",
(void*)cfg, block, off, buffer, size);
lfs2_filebd_t *bd = cfg->context;
// check if write is valid
LFS2_ASSERT(block < cfg->block_count);
LFS2_ASSERT(off % cfg->prog_size == 0);
LFS2_ASSERT(size % cfg->prog_size == 0);
LFS2_ASSERT(block < cfg->block_count);
// check that data was erased? only needed for testing
if (bd->cfg->erase_value != -1) {
off_t res1 = lseek(bd->fd,
(off_t)block*cfg->block_size + (off_t)off, SEEK_SET);
if (res1 < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_prog -> %d", err);
return err;
}
for (lfs2_off_t i = 0; i < size; i++) {
uint8_t c;
ssize_t res2 = read(bd->fd, &c, 1);
if (res2 < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_prog -> %d", err);
return err;
}
LFS2_ASSERT(c == bd->cfg->erase_value);
}
}
LFS2_ASSERT(off+size <= cfg->block_size);
// program data
off_t res1 = lseek(bd->fd,
@@ -170,30 +128,14 @@ int lfs2_filebd_prog(const struct lfs2_config *cfg, lfs2_block_t block,
}
int lfs2_filebd_erase(const struct lfs2_config *cfg, lfs2_block_t block) {
LFS2_FILEBD_TRACE("lfs2_filebd_erase(%p, 0x%"PRIx32")", (void*)cfg, block);
lfs2_filebd_t *bd = cfg->context;
LFS2_FILEBD_TRACE("lfs2_filebd_erase(%p, 0x%"PRIx32" (%"PRIu32"))",
(void*)cfg, block, cfg->block_size);
// check if erase is valid
LFS2_ASSERT(block < cfg->block_count);
// erase, only needed for testing
if (bd->cfg->erase_value != -1) {
off_t res1 = lseek(bd->fd, (off_t)block*cfg->block_size, SEEK_SET);
if (res1 < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_erase -> %d", err);
return err;
}
for (lfs2_off_t i = 0; i < cfg->block_size; i++) {
ssize_t res2 = write(bd->fd, &(uint8_t){bd->cfg->erase_value}, 1);
if (res2 < 0) {
int err = -errno;
LFS2_FILEBD_TRACE("lfs2_filebd_erase -> %d", err);
return err;
}
}
}
// erase is a noop
(void)block;
LFS2_FILEBD_TRACE("lfs2_filebd_erase -> %d", 0);
return 0;
@@ -201,6 +143,7 @@ int lfs2_filebd_erase(const struct lfs2_config *cfg, lfs2_block_t block) {
int lfs2_filebd_sync(const struct lfs2_config *cfg) {
LFS2_FILEBD_TRACE("lfs2_filebd_sync(%p)", (void*)cfg);
// file sync
lfs2_filebd_t *bd = cfg->context;
#ifdef _WIN32