Lines Matching refs:cfg
49 const struct lfs_config *cfg, in lfs_emubd_mutblock() argument
51 lfs_emubd_t *bd = cfg->context; in lfs_emubd_mutblock()
60 sizeof(lfs_emubd_block_t) + bd->cfg->erase_size); in lfs_emubd_mutblock()
66 sizeof(lfs_emubd_block_t) + bd->cfg->erase_size); in lfs_emubd_mutblock()
76 sizeof(lfs_emubd_block_t) + bd->cfg->erase_size); in lfs_emubd_mutblock()
86 (bd->cfg->erase_value != -1) ? bd->cfg->erase_value : 0, in lfs_emubd_mutblock()
87 bd->cfg->erase_size); in lfs_emubd_mutblock()
97 int lfs_emubd_create(const struct lfs_config *cfg, in lfs_emubd_create() argument
107 (void*)cfg, cfg->context, in lfs_emubd_create()
108 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog, in lfs_emubd_create()
109 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, in lfs_emubd_create()
116 lfs_emubd_t *bd = cfg->context; in lfs_emubd_create()
117 bd->cfg = bdcfg; in lfs_emubd_create()
120 bd->blocks = malloc(bd->cfg->erase_count * sizeof(lfs_emubd_block_t*)); in lfs_emubd_create()
125 memset(bd->blocks, 0, bd->cfg->erase_count * sizeof(lfs_emubd_block_t*)); in lfs_emubd_create()
131 bd->power_cycles = bd->cfg->power_cycles; in lfs_emubd_create()
134 if (bd->cfg->disk_path) { in lfs_emubd_create()
144 bd->disk->fd = open(bd->cfg->disk_path, in lfs_emubd_create()
147 bd->disk->fd = open(bd->cfg->disk_path, in lfs_emubd_create()
158 if (bd->cfg->erase_value != -1) { in lfs_emubd_create()
159 bd->disk->scratch = malloc(bd->cfg->erase_size); in lfs_emubd_create()
165 bd->cfg->erase_value, in lfs_emubd_create()
166 bd->cfg->erase_size); in lfs_emubd_create()
170 for (size_t i = 0; i < bd->cfg->erase_count; i++) { in lfs_emubd_create()
173 bd->cfg->erase_size); in lfs_emubd_create()
187 int lfs_emubd_destroy(const struct lfs_config *cfg) { in lfs_emubd_destroy() argument
188 LFS_EMUBD_TRACE("lfs_emubd_destroy(%p)", (void*)cfg); in lfs_emubd_destroy()
189 lfs_emubd_t *bd = cfg->context; in lfs_emubd_destroy()
192 for (lfs_block_t i = 0; i < bd->cfg->erase_count; i++) { in lfs_emubd_destroy()
215 int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, in lfs_emubd_read() argument
219 (void*)cfg, block, off, buffer, size); in lfs_emubd_read()
220 lfs_emubd_t *bd = cfg->context; in lfs_emubd_read()
223 LFS_ASSERT(block < bd->cfg->erase_count); in lfs_emubd_read()
224 LFS_ASSERT(off % bd->cfg->read_size == 0); in lfs_emubd_read()
225 LFS_ASSERT(size % bd->cfg->read_size == 0); in lfs_emubd_read()
226 LFS_ASSERT(off+size <= bd->cfg->erase_size); in lfs_emubd_read()
232 if (bd->cfg->erase_cycles && b->wear >= bd->cfg->erase_cycles && in lfs_emubd_read()
233 bd->cfg->badblock_behavior == LFS_EMUBD_BADBLOCK_READERROR) { in lfs_emubd_read()
243 (bd->cfg->erase_value != -1) ? bd->cfg->erase_value : 0, in lfs_emubd_read()
249 if (bd->cfg->read_sleep) { in lfs_emubd_read()
251 .tv_sec=bd->cfg->read_sleep/1000000000, in lfs_emubd_read()
252 .tv_nsec=bd->cfg->read_sleep%1000000000}, in lfs_emubd_read()
265 int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, in lfs_emubd_prog() argument
269 (void*)cfg, block, off, buffer, size); in lfs_emubd_prog()
270 lfs_emubd_t *bd = cfg->context; in lfs_emubd_prog()
273 LFS_ASSERT(block < bd->cfg->erase_count); in lfs_emubd_prog()
274 LFS_ASSERT(off % bd->cfg->prog_size == 0); in lfs_emubd_prog()
275 LFS_ASSERT(size % bd->cfg->prog_size == 0); in lfs_emubd_prog()
276 LFS_ASSERT(off+size <= bd->cfg->erase_size); in lfs_emubd_prog()
279 lfs_emubd_block_t *b = lfs_emubd_mutblock(cfg, &bd->blocks[block]); in lfs_emubd_prog()
286 if (bd->cfg->erase_cycles && b->wear >= bd->cfg->erase_cycles) { in lfs_emubd_prog()
287 if (bd->cfg->badblock_behavior == in lfs_emubd_prog()
291 } else if (bd->cfg->badblock_behavior == in lfs_emubd_prog()
293 bd->cfg->badblock_behavior == in lfs_emubd_prog()
301 if (bd->cfg->erase_value != -1) { in lfs_emubd_prog()
303 LFS_ASSERT(b->data[off+i] == bd->cfg->erase_value); in lfs_emubd_prog()
313 (off_t)block*bd->cfg->erase_size + (off_t)off, in lfs_emubd_prog()
331 if (bd->cfg->prog_sleep) { in lfs_emubd_prog()
333 .tv_sec=bd->cfg->prog_sleep/1000000000, in lfs_emubd_prog()
334 .tv_nsec=bd->cfg->prog_sleep%1000000000}, in lfs_emubd_prog()
348 bd->cfg->powerloss_cb(bd->cfg->powerloss_data); in lfs_emubd_prog()
356 int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { in lfs_emubd_erase() argument
358 (void*)cfg, block, ((lfs_emubd_t*)cfg->context)->cfg->erase_size); in lfs_emubd_erase()
359 lfs_emubd_t *bd = cfg->context; in lfs_emubd_erase()
362 LFS_ASSERT(block < bd->cfg->erase_count); in lfs_emubd_erase()
365 lfs_emubd_block_t *b = lfs_emubd_mutblock(cfg, &bd->blocks[block]); in lfs_emubd_erase()
372 if (bd->cfg->erase_cycles) { in lfs_emubd_erase()
373 if (b->wear >= bd->cfg->erase_cycles) { in lfs_emubd_erase()
374 if (bd->cfg->badblock_behavior == in lfs_emubd_erase()
378 } else if (bd->cfg->badblock_behavior == in lfs_emubd_erase()
390 if (bd->cfg->erase_value != -1) { in lfs_emubd_erase()
391 memset(b->data, bd->cfg->erase_value, bd->cfg->erase_size); in lfs_emubd_erase()
396 (off_t)block*bd->cfg->erase_size, in lfs_emubd_erase()
406 bd->cfg->erase_size); in lfs_emubd_erase()
416 bd->erased += bd->cfg->erase_size; in lfs_emubd_erase()
417 if (bd->cfg->erase_sleep) { in lfs_emubd_erase()
419 .tv_sec=bd->cfg->erase_sleep/1000000000, in lfs_emubd_erase()
420 .tv_nsec=bd->cfg->erase_sleep%1000000000}, in lfs_emubd_erase()
434 bd->cfg->powerloss_cb(bd->cfg->powerloss_data); in lfs_emubd_erase()
442 int lfs_emubd_sync(const struct lfs_config *cfg) { in lfs_emubd_sync() argument
443 LFS_EMUBD_TRACE("lfs_emubd_sync(%p)", (void*)cfg); in lfs_emubd_sync()
446 (void)cfg; in lfs_emubd_sync()
454 static int lfs_emubd_rawcrc(const struct lfs_config *cfg, in lfs_emubd_rawcrc() argument
456 lfs_emubd_t *bd = cfg->context; in lfs_emubd_rawcrc()
459 LFS_ASSERT(block < cfg->block_count); in lfs_emubd_rawcrc()
465 crc_ = lfs_crc(crc_, b->data, cfg->block_size); in lfs_emubd_rawcrc()
467 uint8_t erase_value = (bd->cfg->erase_value != -1) in lfs_emubd_rawcrc()
468 ? bd->cfg->erase_value in lfs_emubd_rawcrc()
470 for (lfs_size_t i = 0; i < cfg->block_size; i++) { in lfs_emubd_rawcrc()
479 int lfs_emubd_crc(const struct lfs_config *cfg, in lfs_emubd_crc() argument
482 (void*)cfg, block, crc); in lfs_emubd_crc()
483 int err = lfs_emubd_rawcrc(cfg, block, crc); in lfs_emubd_crc()
488 int lfs_emubd_bdcrc(const struct lfs_config *cfg, uint32_t *crc) { in lfs_emubd_bdcrc() argument
489 LFS_EMUBD_TRACE("lfs_emubd_bdcrc(%p, %p)", (void*)cfg, crc); in lfs_emubd_bdcrc()
492 for (lfs_block_t i = 0; i < cfg->block_count; i++) { in lfs_emubd_bdcrc()
494 int err = lfs_emubd_rawcrc(cfg, i, &i_crc); in lfs_emubd_bdcrc()
508 lfs_emubd_sio_t lfs_emubd_readed(const struct lfs_config *cfg) { in lfs_emubd_readed() argument
509 LFS_EMUBD_TRACE("lfs_emubd_readed(%p)", (void*)cfg); in lfs_emubd_readed()
510 lfs_emubd_t *bd = cfg->context; in lfs_emubd_readed()
515 lfs_emubd_sio_t lfs_emubd_proged(const struct lfs_config *cfg) { in lfs_emubd_proged() argument
516 LFS_EMUBD_TRACE("lfs_emubd_proged(%p)", (void*)cfg); in lfs_emubd_proged()
517 lfs_emubd_t *bd = cfg->context; in lfs_emubd_proged()
522 lfs_emubd_sio_t lfs_emubd_erased(const struct lfs_config *cfg) { in lfs_emubd_erased() argument
523 LFS_EMUBD_TRACE("lfs_emubd_erased(%p)", (void*)cfg); in lfs_emubd_erased()
524 lfs_emubd_t *bd = cfg->context; in lfs_emubd_erased()
529 int lfs_emubd_setreaded(const struct lfs_config *cfg, lfs_emubd_io_t readed) { in lfs_emubd_setreaded() argument
530 LFS_EMUBD_TRACE("lfs_emubd_setreaded(%p, %"PRIu64")", (void*)cfg, readed); in lfs_emubd_setreaded()
531 lfs_emubd_t *bd = cfg->context; in lfs_emubd_setreaded()
537 int lfs_emubd_setproged(const struct lfs_config *cfg, lfs_emubd_io_t proged) { in lfs_emubd_setproged() argument
538 LFS_EMUBD_TRACE("lfs_emubd_setproged(%p, %"PRIu64")", (void*)cfg, proged); in lfs_emubd_setproged()
539 lfs_emubd_t *bd = cfg->context; in lfs_emubd_setproged()
545 int lfs_emubd_seterased(const struct lfs_config *cfg, lfs_emubd_io_t erased) { in lfs_emubd_seterased() argument
546 LFS_EMUBD_TRACE("lfs_emubd_seterased(%p, %"PRIu64")", (void*)cfg, erased); in lfs_emubd_seterased()
547 lfs_emubd_t *bd = cfg->context; in lfs_emubd_seterased()
553 lfs_emubd_swear_t lfs_emubd_wear(const struct lfs_config *cfg, in lfs_emubd_wear() argument
555 LFS_EMUBD_TRACE("lfs_emubd_wear(%p, %"PRIu32")", (void*)cfg, block); in lfs_emubd_wear()
556 lfs_emubd_t *bd = cfg->context; in lfs_emubd_wear()
559 LFS_ASSERT(block < bd->cfg->erase_count); in lfs_emubd_wear()
574 int lfs_emubd_setwear(const struct lfs_config *cfg, in lfs_emubd_setwear() argument
577 (void*)cfg, block, wear); in lfs_emubd_setwear()
578 lfs_emubd_t *bd = cfg->context; in lfs_emubd_setwear()
581 LFS_ASSERT(block < bd->cfg->erase_count); in lfs_emubd_setwear()
584 lfs_emubd_block_t *b = lfs_emubd_mutblock(cfg, &bd->blocks[block]); in lfs_emubd_setwear()
596 const struct lfs_config *cfg) { in lfs_emubd_powercycles() argument
597 LFS_EMUBD_TRACE("lfs_emubd_powercycles(%p)", (void*)cfg); in lfs_emubd_powercycles()
598 lfs_emubd_t *bd = cfg->context; in lfs_emubd_powercycles()
604 int lfs_emubd_setpowercycles(const struct lfs_config *cfg, in lfs_emubd_setpowercycles() argument
607 (void*)cfg, power_cycles); in lfs_emubd_setpowercycles()
608 lfs_emubd_t *bd = cfg->context; in lfs_emubd_setpowercycles()
616 int lfs_emubd_copy(const struct lfs_config *cfg, lfs_emubd_t *copy) { in lfs_emubd_copy() argument
617 LFS_EMUBD_TRACE("lfs_emubd_copy(%p, %p)", (void*)cfg, (void*)copy); in lfs_emubd_copy()
618 lfs_emubd_t *bd = cfg->context; in lfs_emubd_copy()
621 copy->blocks = malloc(bd->cfg->erase_count * sizeof(lfs_emubd_block_t*)); in lfs_emubd_copy()
627 for (size_t i = 0; i < bd->cfg->erase_count; i++) { in lfs_emubd_copy()
640 copy->cfg = bd->cfg; in lfs_emubd_copy()