emubd/kiwibd: Fixed unused path param, dropped disk_path
For some reason emubd had both a path argument to lfs3_emubd_create, and a disk_path config option, with only the disk_path actually being used. But the real curiosity is why did GCC only starting warning about it when copied to kiwibd? path is clearly unused in lfs3_emubd_createcfg, but no warning... --- Anyways, not sure which one is a better API, but we definitely don't need two APIs, so eeny meeny miny moe... Went ahead and chose the lfs3_emubd_create path param for some consistency with filebd.
This commit is contained in:
+69
-29
@@ -166,23 +166,52 @@ static uint32_t lfs3_emubd_prng_(uint32_t *state) {
|
|||||||
|
|
||||||
int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
||||||
const struct lfs3_emubd_cfg *bdcfg) {
|
const struct lfs3_emubd_cfg *bdcfg) {
|
||||||
LFS3_EMUBD_TRACE("lfs3_emubd_createcfg(%p {.context=%p, "
|
LFS3_EMUBD_TRACE("lfs3_emubd_createcfg("
|
||||||
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
|
"%p {"
|
||||||
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
|
".context=%p, "
|
||||||
".block_size=%"PRIu32", .block_count=%"PRIu32"}, "
|
".read=%p, "
|
||||||
|
".prog=%p, "
|
||||||
|
".erase=%p, "
|
||||||
|
".sync=%p, "
|
||||||
|
".read_size=%"PRIu32", "
|
||||||
|
".prog_size=%"PRIu32", "
|
||||||
|
".block_size=%"PRIu32", "
|
||||||
|
".block_count=%"PRIu32"}, "
|
||||||
"\"%s\", "
|
"\"%s\", "
|
||||||
"%p {.erase_value=%"PRId32", .erase_cycles=%"PRIu32", "
|
"%p {.erase_value=%"PRId32", "
|
||||||
".badblock_behavior=%"PRIu8", .power_cycles=%"PRIu32", "
|
".erase_cycles=%"PRIu32", "
|
||||||
".powerloss_behavior=%"PRIu8", .powerloss_cb=%p, "
|
".badblock_behavior=%"PRIu8", "
|
||||||
".powerloss_data=%p, seed=%"PRIu32"})",
|
".power_cycles=%"PRIu32", "
|
||||||
(void*)cfg, cfg->context,
|
".powerloss_behavior=%"PRIu8", "
|
||||||
(void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
|
".powerloss_cb=%p, "
|
||||||
(void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
|
".powerloss_data=%p, "
|
||||||
cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
|
".seed=%"PRIu32", "
|
||||||
path, (void*)bdcfg, bdcfg->erase_value, bdcfg->erase_cycles,
|
".read_sleep=%"PRIu64", "
|
||||||
bdcfg->badblock_behavior, bdcfg->power_cycles,
|
".prog_sleep=%"PRIu64", "
|
||||||
bdcfg->powerloss_behavior, (void*)(uintptr_t)bdcfg->powerloss_cb,
|
".erase_sleep=%"PRIu64"})",
|
||||||
bdcfg->powerloss_data, bdcfg->seed);
|
(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,
|
||||||
|
bdcfg->erase_cycles,
|
||||||
|
bdcfg->badblock_behavior,
|
||||||
|
bdcfg->power_cycles,
|
||||||
|
bdcfg->powerloss_behavior,
|
||||||
|
(void*)(uintptr_t)bdcfg->powerloss_cb,
|
||||||
|
bdcfg->powerloss_data,
|
||||||
|
bdcfg->seed,
|
||||||
|
bdcfg->read_sleep,
|
||||||
|
bdcfg->prog_sleep,
|
||||||
|
bdcfg->erase_sleep);
|
||||||
lfs3_emubd_t *bd = cfg->context;
|
lfs3_emubd_t *bd = cfg->context;
|
||||||
bd->cfg = bdcfg;
|
bd->cfg = bdcfg;
|
||||||
|
|
||||||
@@ -229,7 +258,7 @@ int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
cfg->block_count * sizeof(lfs3_emubd_block_t*));
|
cfg->block_count * sizeof(lfs3_emubd_block_t*));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bd->cfg->disk_path) {
|
if (path) {
|
||||||
bd->disk = malloc(sizeof(lfs3_emubd_disk_t));
|
bd->disk = malloc(sizeof(lfs3_emubd_disk_t));
|
||||||
if (!bd->disk) {
|
if (!bd->disk) {
|
||||||
err = LFS3_ERR_NOMEM;
|
err = LFS3_ERR_NOMEM;
|
||||||
@@ -240,11 +269,9 @@ int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
bd->disk->scratch = NULL;
|
bd->disk->scratch = NULL;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
bd->disk->fd = open(bd->cfg->disk_path,
|
bd->disk->fd = open(path, O_RDWR | O_CREAT | O_BINARY, 0666);
|
||||||
O_RDWR | O_CREAT | O_BINARY, 0666);
|
|
||||||
#else
|
#else
|
||||||
bd->disk->fd = open(bd->cfg->disk_path,
|
bd->disk->fd = open(path, O_RDWR | O_CREAT, 0666);
|
||||||
O_RDWR | O_CREAT, 0666);
|
|
||||||
#endif
|
#endif
|
||||||
if (bd->disk->fd < 0) {
|
if (bd->disk->fd < 0) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
@@ -293,15 +320,28 @@ failed:;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int lfs3_emubd_create(const struct lfs3_cfg *cfg, const char *path) {
|
int lfs3_emubd_create(const struct lfs3_cfg *cfg, const char *path) {
|
||||||
LFS3_EMUBD_TRACE("lfs3_emubd_create(%p {.context=%p, "
|
LFS3_EMUBD_TRACE("lfs3_emubd_create("
|
||||||
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
|
"%p {"
|
||||||
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
|
".context=%p, "
|
||||||
".block_size=%"PRIu32", .block_count=%"PRIu32"}, "
|
".read=%p, "
|
||||||
|
".prog=%p, "
|
||||||
|
".erase=%p, "
|
||||||
|
".sync=%p, "
|
||||||
|
".read_size=%"PRIu32", "
|
||||||
|
".prog_size=%"PRIu32", "
|
||||||
|
".block_size=%"PRIu32", "
|
||||||
|
".block_count=%"PRIu32"}, "
|
||||||
"\"%s\")",
|
"\"%s\")",
|
||||||
(void*)cfg, cfg->context,
|
(void*)cfg,
|
||||||
(void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
|
cfg->context,
|
||||||
(void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
|
(void*)(uintptr_t)cfg->read,
|
||||||
cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
|
(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);
|
path);
|
||||||
static const struct lfs3_emubd_cfg defaults = {.erase_value=-1};
|
static const struct lfs3_emubd_cfg defaults = {.erase_value=-1};
|
||||||
int err = lfs3_emubd_createcfg(cfg, path, &defaults);
|
int err = lfs3_emubd_createcfg(cfg, path, &defaults);
|
||||||
|
|||||||
+3
-9
@@ -100,11 +100,6 @@ struct lfs3_emubd_cfg {
|
|||||||
// not affect normal operation.
|
// not affect normal operation.
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
|
|
||||||
// Path to file to use as a mirror of the disk. This provides a way to view
|
|
||||||
// the current state of the block device, but does not eliminate the RAM
|
|
||||||
// requirement.
|
|
||||||
const char *disk_path;
|
|
||||||
|
|
||||||
// Artificial delay in nanoseconds, there is no purpose for this other
|
// Artificial delay in nanoseconds, there is no purpose for this other
|
||||||
// than slowing down the simulation.
|
// than slowing down the simulation.
|
||||||
lfs3_emubd_sleep_t read_sleep;
|
lfs3_emubd_sleep_t read_sleep;
|
||||||
@@ -160,11 +155,10 @@ typedef struct lfs3_emubd {
|
|||||||
|
|
||||||
// Create an emulating block device using the geometry in lfs3_cfg
|
// Create an emulating block device using the geometry in lfs3_cfg
|
||||||
//
|
//
|
||||||
// If disk_path is provided, emubd will mirror the block device in the
|
// If path is provided, emubd will mirror the block device in the file.
|
||||||
// file. Note this is a write-only mirror intended for introspection,
|
// This provides a way to view the current state of the block device,
|
||||||
// and does not eliminate the RAM requirement.
|
// but does not eliminate the RAM requirement.
|
||||||
//
|
//
|
||||||
// TODO wait, why do we have both disk_path and path here?
|
|
||||||
int lfs3_emubd_create(const struct lfs3_cfg *cfg, const char *path);
|
int lfs3_emubd_create(const struct lfs3_cfg *cfg, const char *path);
|
||||||
int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
int lfs3_emubd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
||||||
const struct lfs3_emubd_cfg *bdcfg);
|
const struct lfs3_emubd_cfg *bdcfg);
|
||||||
|
|||||||
+38
-43
@@ -92,7 +92,6 @@ int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
"\"%s\", "
|
"\"%s\", "
|
||||||
"%p {"
|
"%p {"
|
||||||
".erase_value=%"PRId32", "
|
".erase_value=%"PRId32", "
|
||||||
".disk_path=\"%s\", "
|
|
||||||
".buffer=%p, "
|
".buffer=%p, "
|
||||||
".read_sleep=%"PRIu64", "
|
".read_sleep=%"PRIu64", "
|
||||||
".prog_sleep=%"PRIu64", "
|
".prog_sleep=%"PRIu64", "
|
||||||
@@ -110,7 +109,6 @@ int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
path,
|
path,
|
||||||
(void*)bdcfg,
|
(void*)bdcfg,
|
||||||
bdcfg->erase_value,
|
bdcfg->erase_value,
|
||||||
bdcfg->disk_path,
|
|
||||||
bdcfg->buffer,
|
bdcfg->buffer,
|
||||||
bdcfg->read_sleep,
|
bdcfg->read_sleep,
|
||||||
bdcfg->prog_sleep,
|
bdcfg->prog_sleep,
|
||||||
@@ -122,35 +120,34 @@ int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
bd->readed = 0;
|
bd->readed = 0;
|
||||||
bd->proged = 0;
|
bd->proged = 0;
|
||||||
bd->erased = 0;
|
bd->erased = 0;
|
||||||
if (bd->cfg->disk_path) {
|
bd->fd = -1;
|
||||||
bd->u.disk.fd = -1;
|
if (path) {
|
||||||
bd->u.disk.scratch = NULL;
|
bd->u.scratch = NULL;
|
||||||
} else {
|
} else {
|
||||||
bd->u.mem = NULL;
|
bd->u.mem = NULL;
|
||||||
}
|
}
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
// if we have a disk_path, try to open the backing file
|
// if we have a path, try to open the backing file
|
||||||
if (bd->cfg->disk_path) {
|
if (path) {
|
||||||
bd->u.disk.fd = open(bd->cfg->disk_path,
|
bd->fd = open(path, O_RDWR | O_CREAT, 0666);
|
||||||
O_RDWR | O_CREAT, 0666);
|
if (bd->fd < 0) {
|
||||||
if (bd->u.disk.fd < 0) {
|
|
||||||
err = -errno;
|
err = -errno;
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate a scratch buffer to help with zeroing/masking/etc
|
// allocate a scratch buffer to help with zeroing/masking/etc
|
||||||
bd->u.disk.scratch = malloc(cfg->block_size);
|
bd->u.scratch = malloc(cfg->block_size);
|
||||||
if (!bd->u.disk.scratch) {
|
if (!bd->u.scratch) {
|
||||||
err = LFS3_ERR_NOMEM;
|
err = LFS3_ERR_NOMEM;
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// zero for reproducibility
|
// zero for reproducibility
|
||||||
lfs3_kiwibd_memzero(cfg, bd->u.disk.scratch, cfg->block_size);
|
lfs3_kiwibd_memzero(cfg, bd->u.scratch, cfg->block_size);
|
||||||
for (lfs3_block_t i = 0; i < cfg->block_count; i++) {
|
for (lfs3_block_t i = 0; i < cfg->block_count; i++) {
|
||||||
ssize_t res = write(bd->u.disk.fd,
|
ssize_t res = write(bd->fd,
|
||||||
bd->u.disk.scratch,
|
bd->u.scratch,
|
||||||
cfg->block_size);
|
cfg->block_size);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
err = -errno;
|
err = -errno;
|
||||||
@@ -177,11 +174,9 @@ int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
|||||||
failed:;
|
failed:;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_createcfg -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_createcfg -> %d", err);
|
||||||
// clean up memory
|
// clean up memory
|
||||||
if (bd->cfg->disk_path) {
|
if (bd->fd >= 0) {
|
||||||
if (bd->u.disk.fd != -1) {
|
close(bd->fd);
|
||||||
close(bd->u.disk.fd);
|
free(bd->u.scratch);
|
||||||
}
|
|
||||||
free(bd->u.disk.scratch);
|
|
||||||
} else {
|
} else {
|
||||||
free(bd->u.mem);
|
free(bd->u.mem);
|
||||||
}
|
}
|
||||||
@@ -223,9 +218,9 @@ int lfs3_kiwibd_destroy(const struct lfs3_cfg *cfg) {
|
|||||||
lfs3_kiwibd_t *bd = cfg->context;
|
lfs3_kiwibd_t *bd = cfg->context;
|
||||||
|
|
||||||
// clean up memory
|
// clean up memory
|
||||||
if (bd->cfg->disk_path) {
|
if (bd->fd >= 0) {
|
||||||
close(bd->u.disk.fd);
|
close(bd->fd);
|
||||||
free(bd->u.disk.scratch);
|
free(bd->u.scratch);
|
||||||
} else {
|
} else {
|
||||||
free(bd->u.mem);
|
free(bd->u.mem);
|
||||||
}
|
}
|
||||||
@@ -251,12 +246,12 @@ int lfs3_kiwibd_read(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
LFS3_ASSERT(off+size <= cfg->block_size);
|
LFS3_ASSERT(off+size <= cfg->block_size);
|
||||||
|
|
||||||
// read in file?
|
// read in file?
|
||||||
if (bd->cfg->disk_path) {
|
if (bd->fd >= 0) {
|
||||||
lfs3_kiwibd_memerase(cfg,
|
lfs3_kiwibd_memerase(cfg,
|
||||||
bd->u.disk.scratch,
|
bd->u.scratch,
|
||||||
cfg->block_size);
|
cfg->block_size);
|
||||||
|
|
||||||
off_t res = lseek(bd->u.disk.fd,
|
off_t res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size + (off_t)off,
|
(off_t)block*cfg->block_size + (off_t)off,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -265,7 +260,7 @@ int lfs3_kiwibd_read(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t res_ = read(bd->u.disk.fd, buffer, size);
|
ssize_t res_ = read(bd->fd, buffer, size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_read -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_read -> %d", err);
|
||||||
@@ -312,10 +307,10 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
LFS3_ASSERT(off+size <= cfg->block_size);
|
LFS3_ASSERT(off+size <= cfg->block_size);
|
||||||
|
|
||||||
// prog in file?
|
// prog in file?
|
||||||
if (bd->cfg->disk_path) {
|
if (bd->fd >= 0) {
|
||||||
// were we erased properly?
|
// were we erased properly?
|
||||||
if (bd->cfg->erase_value >= 0) {
|
if (bd->cfg->erase_value >= 0) {
|
||||||
off_t res = lseek(bd->u.disk.fd,
|
off_t res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size + (off_t)off,
|
(off_t)block*cfg->block_size + (off_t)off,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -324,7 +319,7 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t res_ = read(bd->u.disk.fd, bd->u.disk.scratch, size);
|
ssize_t res_ = read(bd->fd, bd->u.scratch, size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
||||||
@@ -332,13 +327,13 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (lfs3_off_t i = 0; i < size; i++) {
|
for (lfs3_off_t i = 0; i < size; i++) {
|
||||||
LFS3_ASSERT(bd->u.disk.scratch[i] == bd->cfg->erase_value);
|
LFS3_ASSERT(bd->u.scratch[i] == bd->cfg->erase_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// masking progs?
|
// masking progs?
|
||||||
if (bd->cfg->erase_value == -2) {
|
if (bd->cfg->erase_value == -2) {
|
||||||
off_t res = lseek(bd->u.disk.fd,
|
off_t res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size + (off_t)off,
|
(off_t)block*cfg->block_size + (off_t)off,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -347,16 +342,16 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t res_ = read(bd->u.disk.fd, bd->u.disk.scratch, size);
|
ssize_t res_ = read(bd->fd, bd->u.scratch, size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfs3_kiwibd_memprog(cfg, bd->u.disk.scratch, buffer, size);
|
lfs3_kiwibd_memprog(cfg, bd->u.scratch, buffer, size);
|
||||||
|
|
||||||
res = lseek(bd->u.disk.fd,
|
res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size + (off_t)off,
|
(off_t)block*cfg->block_size + (off_t)off,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -365,7 +360,7 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
res_ = write(bd->u.disk.fd, bd->u.disk.scratch, size);
|
res_ = write(bd->fd, bd->u.scratch, size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
||||||
@@ -374,7 +369,7 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
|
|
||||||
// normal progs?
|
// normal progs?
|
||||||
} else {
|
} else {
|
||||||
off_t res = lseek(bd->u.disk.fd,
|
off_t res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size + (off_t)off,
|
(off_t)block*cfg->block_size + (off_t)off,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -383,7 +378,7 @@ int lfs3_kiwibd_prog(const struct lfs3_cfg *cfg, lfs3_block_t block,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t res_ = write(bd->u.disk.fd, buffer, size);
|
ssize_t res_ = write(bd->fd, buffer, size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
LFS3_KIWIBD_TRACE("lfs3_kiwibd_prog -> %d", err);
|
||||||
@@ -437,8 +432,8 @@ int lfs3_kiwibd_erase(const struct lfs3_cfg *cfg, lfs3_block_t block) {
|
|||||||
// emulate an erase value?
|
// emulate an erase value?
|
||||||
if (bd->cfg->erase_value != -1) {
|
if (bd->cfg->erase_value != -1) {
|
||||||
// erase in file?
|
// erase in file?
|
||||||
if (bd->cfg->disk_path) {
|
if (bd->fd >= 0) {
|
||||||
off_t res = lseek(bd->u.disk.fd,
|
off_t res = lseek(bd->fd,
|
||||||
(off_t)block*cfg->block_size,
|
(off_t)block*cfg->block_size,
|
||||||
SEEK_SET);
|
SEEK_SET);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
@@ -448,11 +443,11 @@ int lfs3_kiwibd_erase(const struct lfs3_cfg *cfg, lfs3_block_t block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lfs3_kiwibd_memerase(cfg,
|
lfs3_kiwibd_memerase(cfg,
|
||||||
bd->u.disk.scratch,
|
bd->u.scratch,
|
||||||
cfg->block_size);
|
cfg->block_size);
|
||||||
|
|
||||||
ssize_t res_ = write(bd->u.disk.fd,
|
ssize_t res_ = write(bd->fd,
|
||||||
bd->u.disk.scratch,
|
bd->u.scratch,
|
||||||
cfg->block_size);
|
cfg->block_size);
|
||||||
if (res_ < 0) {
|
if (res_ < 0) {
|
||||||
int err = -errno;
|
int err = -errno;
|
||||||
|
|||||||
+4
-11
@@ -39,10 +39,6 @@ struct lfs3_kiwibd_cfg {
|
|||||||
// does _not_ rely on this!).
|
// does _not_ rely on this!).
|
||||||
int32_t erase_value;
|
int32_t erase_value;
|
||||||
|
|
||||||
// Path to file to back the block device. If provided kiwibd uses this
|
|
||||||
// instead of RAM, allowing emulation of block devices > available RAM.
|
|
||||||
const char *disk_path;
|
|
||||||
|
|
||||||
// Optional statically allocated buffer for the block device. Ignored
|
// Optional statically allocated buffer for the block device. Ignored
|
||||||
// if disk_path is provided.
|
// if disk_path is provided.
|
||||||
void *buffer;
|
void *buffer;
|
||||||
@@ -63,11 +59,9 @@ struct lfs3_kiwibd_cfg {
|
|||||||
// kiwibd state
|
// kiwibd state
|
||||||
typedef struct lfs3_kiwibd {
|
typedef struct lfs3_kiwibd {
|
||||||
// backing disk
|
// backing disk
|
||||||
|
int fd;
|
||||||
union {
|
union {
|
||||||
struct {
|
uint8_t *scratch;
|
||||||
int fd;
|
|
||||||
uint8_t *scratch;
|
|
||||||
} disk;
|
|
||||||
uint8_t *mem;
|
uint8_t *mem;
|
||||||
} u;
|
} u;
|
||||||
|
|
||||||
@@ -84,10 +78,9 @@ typedef struct lfs3_kiwibd {
|
|||||||
|
|
||||||
// Create a kiwibd using the geometry in lfs3_cfg
|
// Create a kiwibd using the geometry in lfs3_cfg
|
||||||
//
|
//
|
||||||
// If disk_path is provided, it will be used to back the kiwibd,
|
// If path is provided, kiwibd will use the file to back the block
|
||||||
// otherwise kiwibd will try to use RAM.
|
// device, allowing emulation of block devices > available RAM.
|
||||||
//
|
//
|
||||||
// TODO wait, why do we have both disk_path and path here?
|
|
||||||
int lfs3_kiwibd_create(const struct lfs3_cfg *cfg, const char *path);
|
int lfs3_kiwibd_create(const struct lfs3_cfg *cfg, const char *path);
|
||||||
int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
int lfs3_kiwibd_createcfg(const struct lfs3_cfg *cfg, const char *path,
|
||||||
const struct lfs3_kiwibd_cfg *bdcfg);
|
const struct lfs3_kiwibd_cfg *bdcfg);
|
||||||
|
|||||||
@@ -1355,7 +1355,6 @@ void perm_run(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = bench_disk_path,
|
|
||||||
.read_sleep = bench_read_sleep,
|
.read_sleep = bench_read_sleep,
|
||||||
.prog_sleep = bench_prog_sleep,
|
.prog_sleep = bench_prog_sleep,
|
||||||
.erase_sleep = bench_erase_sleep,
|
.erase_sleep = bench_erase_sleep,
|
||||||
|
|||||||
@@ -1319,7 +1319,6 @@ static void run_powerloss_none(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = test_disk_path,
|
|
||||||
.read_sleep = test_read_sleep,
|
.read_sleep = test_read_sleep,
|
||||||
.prog_sleep = test_prog_sleep,
|
.prog_sleep = test_prog_sleep,
|
||||||
.erase_sleep = test_erase_sleep,
|
.erase_sleep = test_erase_sleep,
|
||||||
@@ -1380,7 +1379,6 @@ static void run_powerloss_linear(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = test_disk_path,
|
|
||||||
.read_sleep = test_read_sleep,
|
.read_sleep = test_read_sleep,
|
||||||
.prog_sleep = test_prog_sleep,
|
.prog_sleep = test_prog_sleep,
|
||||||
.erase_sleep = test_erase_sleep,
|
.erase_sleep = test_erase_sleep,
|
||||||
@@ -1457,7 +1455,6 @@ static void run_powerloss_log(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = test_disk_path,
|
|
||||||
.read_sleep = test_read_sleep,
|
.read_sleep = test_read_sleep,
|
||||||
.prog_sleep = test_prog_sleep,
|
.prog_sleep = test_prog_sleep,
|
||||||
.erase_sleep = test_erase_sleep,
|
.erase_sleep = test_erase_sleep,
|
||||||
@@ -1534,7 +1531,6 @@ static void run_powerloss_cycles(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = test_disk_path,
|
|
||||||
.read_sleep = test_read_sleep,
|
.read_sleep = test_read_sleep,
|
||||||
.prog_sleep = test_prog_sleep,
|
.prog_sleep = test_prog_sleep,
|
||||||
.erase_sleep = test_erase_sleep,
|
.erase_sleep = test_erase_sleep,
|
||||||
@@ -1709,7 +1705,6 @@ static void run_powerloss_exhaustive(
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lfs3_emubd_cfg bdcfg = {
|
struct lfs3_emubd_cfg bdcfg = {
|
||||||
.disk_path = test_disk_path,
|
|
||||||
.read_sleep = test_read_sleep,
|
.read_sleep = test_read_sleep,
|
||||||
.prog_sleep = test_prog_sleep,
|
.prog_sleep = test_prog_sleep,
|
||||||
.erase_sleep = test_erase_sleep,
|
.erase_sleep = test_erase_sleep,
|
||||||
|
|||||||
Reference in New Issue
Block a user