Lines Matching refs:cfg
44 memset(pcache->buffer, 0xff, lfs->cfg->cache_size); in lfs_cache_zero()
53 if (block >= lfs->cfg->block_count || in lfs_bd_read()
54 off+size > lfs->cfg->block_size) { in lfs_bd_read()
95 if (size >= hint && off % lfs->cfg->read_size == 0 && in lfs_bd_read()
96 size >= lfs->cfg->read_size) { in lfs_bd_read()
98 diff = lfs_aligndown(diff, lfs->cfg->read_size); in lfs_bd_read()
99 int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); in lfs_bd_read()
111 LFS_ASSERT(block < lfs->cfg->block_count); in lfs_bd_read()
113 rcache->off = lfs_aligndown(off, lfs->cfg->read_size); in lfs_bd_read()
116 lfs_alignup(off+hint, lfs->cfg->read_size), in lfs_bd_read()
117 lfs->cfg->block_size) in lfs_bd_read()
119 lfs->cfg->cache_size); in lfs_bd_read()
120 int err = lfs->cfg->read(lfs->cfg, rcache->block, in lfs_bd_read()
162 LFS_ASSERT(pcache->block < lfs->cfg->block_count); in lfs_bd_flush()
163 lfs_size_t diff = lfs_alignup(pcache->size, lfs->cfg->prog_size); in lfs_bd_flush()
164 int err = lfs->cfg->prog(lfs->cfg, pcache->block, in lfs_bd_flush()
203 err = lfs->cfg->sync(lfs->cfg); in lfs_bd_sync()
215 LFS_ASSERT(block == LFS_BLOCK_INLINE || block < lfs->cfg->block_count); in lfs_bd_prog()
216 LFS_ASSERT(off + size <= lfs->cfg->block_size); in lfs_bd_prog()
221 off < pcache->off + lfs->cfg->cache_size) { in lfs_bd_prog()
224 lfs->cfg->cache_size - (off-pcache->off)); in lfs_bd_prog()
232 if (pcache->size == lfs->cfg->cache_size) { in lfs_bd_prog()
249 pcache->off = lfs_aligndown(off, lfs->cfg->prog_size); in lfs_bd_prog()
259 LFS_ASSERT(block < lfs->cfg->block_count); in lfs_bd_erase()
260 int err = lfs->cfg->erase(lfs->cfg, block); in lfs_bd_erase()
537 + lfs->cfg->block_count) % lfs->cfg->block_count; in lfs_alloc_lookahead()
551 lfs->free.ack = lfs->cfg->block_count; in lfs_alloc_ack()
572 *block = (lfs->free.off + off) % lfs->cfg->block_count; in lfs_alloc()
595 % lfs->cfg->block_count; in lfs_alloc()
596 lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size, lfs->free.ack); in lfs_alloc()
600 memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size); in lfs_alloc()
685 if (off+size > lfs->cfg->block_size) { in lfs_dir_getread()
728 rcache->off = lfs_aligndown(off, lfs->cfg->read_size); in lfs_dir_getread()
729 rcache->size = lfs_min(lfs_alignup(off+hint, lfs->cfg->read_size), in lfs_dir_getread()
730 lfs->cfg->cache_size); in lfs_dir_getread()
1012 if (pair[0] >= lfs->cfg->block_count || pair[1] >= lfs->cfg->block_count) { in lfs_dir_fetchmatch()
1058 NULL, &lfs->rcache, lfs->cfg->block_size, in lfs_dir_fetchmatch()
1075 dir->off % lfs->cfg->prog_size == 0); in lfs_dir_fetchmatch()
1077 } else if (off + lfs_tag_dsize(tag) > lfs->cfg->block_size) { in lfs_dir_fetchmatch()
1088 NULL, &lfs->rcache, lfs->cfg->block_size, in lfs_dir_fetchmatch()
1131 NULL, &lfs->rcache, lfs->cfg->block_size, in lfs_dir_fetchmatch()
1164 NULL, &lfs->rcache, lfs->cfg->block_size, in lfs_dir_fetchmatch()
1508 lfs->cfg->prog_size); in lfs_dir_commitcrc()
1632 if (lfs->cfg->block_cycles > 0) { in lfs_dir_alloc()
1633 dir->rev = lfs_alignup(dir->rev, ((lfs->cfg->block_cycles+1)|1)); in lfs_dir_alloc()
1738 return (lfs->cfg->block_cycles > 0 in lfs_dir_needsrelocation()
1739 && ((dir->rev + 1) % ((lfs->cfg->block_cycles+1)|1) == 0)); in lfs_dir_needsrelocation()
1782 .end = (lfs->cfg->metadata_max ? in lfs_dir_compact()
1783 lfs->cfg->metadata_max : lfs->cfg->block_size) - 8, in lfs_dir_compact()
1874 LFS_ASSERT(commit.off % lfs->cfg->prog_size == 0); in lfs_dir_compact()
1944 && size <= lfs_min(lfs->cfg->block_size - 36, in lfs_dir_splittingcompact()
1946 (lfs->cfg->metadata_max in lfs_dir_splittingcompact()
1947 ? lfs->cfg->metadata_max in lfs_dir_splittingcompact()
1948 : lfs->cfg->block_size)/2, in lfs_dir_splittingcompact()
1949 lfs->cfg->prog_size))) { in lfs_dir_splittingcompact()
1990 if ((lfs_size_t)size < lfs->cfg->block_count/2) { in lfs_dir_splittingcompact()
2059 .end = (lfs->cfg->metadata_max ? in lfs_dir_relocatingcommit()
2060 lfs->cfg->metadata_max : lfs->cfg->block_size) - 8, in lfs_dir_relocatingcommit()
2112 LFS_ASSERT(commit.off % lfs->cfg->prog_size == 0); in lfs_dir_relocatingcommit()
2191 f->ctz.size > lfs->cfg->cache_size) { in lfs_dir_orphaningcommit()
2651 lfs_off_t b = lfs->cfg->block_size - 2*4; in lfs_ctz_index()
2729 if (noff != lfs->cfg->block_size) { in lfs_ctz_extend()
2843 const struct lfs_file_config *cfg) { argument
2858 file->cfg = cfg;
2932 for (unsigned i = 0; i < file->cfg->attr_count; i++) {
2937 LFS_MKTAG(LFS_TYPE_USERATTR + file->cfg->attrs[i].type,
2938 file->id, file->cfg->attrs[i].size),
2939 file->cfg->attrs[i].buffer);
2949 if (file->cfg->attrs[i].size > lfs->attr_max) {
2960 if (file->cfg->buffer) {
2961 file->cache.buffer = file->cfg->buffer;
2963 file->cache.buffer = lfs_malloc(lfs->cfg->cache_size);
2980 file->cache.size = lfs->cfg->cache_size;
3025 if (!file->cfg->buffer) {
3085 memcpy(file->cache.buffer, lfs->pcache.buffer, lfs->cfg->cache_size);
3238 file->cfg->attr_count), file->cfg->attrs}));
3267 file->off == lfs->cfg->block_size) {
3284 lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off);
3287 NULL, &file->cache, lfs->cfg->block_size,
3296 NULL, &file->cache, lfs->cfg->block_size,
3339 lfs->cfg->cache_size,
3340 (lfs->cfg->metadata_max ?
3341 lfs->cfg->metadata_max : lfs->cfg->block_size) / 8))) {
3353 file->off == lfs->cfg->block_size) {
3387 lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off);
3912 static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { argument
3913 lfs->cfg = cfg;
3918 LFS_ASSERT(lfs->cfg->read_size != 0);
3919 LFS_ASSERT(lfs->cfg->prog_size != 0);
3920 LFS_ASSERT(lfs->cfg->cache_size != 0);
3924 LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0);
3925 LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0);
3926 LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0);
3929 LFS_ASSERT(4*lfs_npw2(0xffffffff / (lfs->cfg->block_size-2*4))
3930 <= lfs->cfg->block_size);
3938 LFS_ASSERT(lfs->cfg->block_cycles != 0);
3942 if (lfs->cfg->read_buffer) {
3943 lfs->rcache.buffer = lfs->cfg->read_buffer;
3945 lfs->rcache.buffer = lfs_malloc(lfs->cfg->cache_size);
3953 if (lfs->cfg->prog_buffer) {
3954 lfs->pcache.buffer = lfs->cfg->prog_buffer;
3956 lfs->pcache.buffer = lfs_malloc(lfs->cfg->cache_size);
3968 LFS_ASSERT(lfs->cfg->lookahead_size > 0);
3969 LFS_ASSERT(lfs->cfg->lookahead_size % 8 == 0 &&
3970 (uintptr_t)lfs->cfg->lookahead_buffer % 4 == 0);
3971 if (lfs->cfg->lookahead_buffer) {
3972 lfs->free.buffer = lfs->cfg->lookahead_buffer;
3974 lfs->free.buffer = lfs_malloc(lfs->cfg->lookahead_size);
3982 LFS_ASSERT(lfs->cfg->name_max <= LFS_NAME_MAX);
3983 lfs->name_max = lfs->cfg->name_max;
3988 LFS_ASSERT(lfs->cfg->file_max <= LFS_FILE_MAX);
3989 lfs->file_max = lfs->cfg->file_max;
3994 LFS_ASSERT(lfs->cfg->attr_max <= LFS_ATTR_MAX);
3995 lfs->attr_max = lfs->cfg->attr_max;
4000 LFS_ASSERT(lfs->cfg->metadata_max <= lfs->cfg->block_size);
4023 if (!lfs->cfg->read_buffer) {
4027 if (!lfs->cfg->prog_buffer) {
4031 if (!lfs->cfg->lookahead_buffer) {
4039 static int lfs_rawformat(lfs_t *lfs, const struct lfs_config *cfg) { argument
4042 err = lfs_init(lfs, cfg);
4048 memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size);
4050 lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size,
4051 lfs->cfg->block_count);
4065 .block_size = lfs->cfg->block_size,
4066 .block_count = lfs->cfg->block_count,
4104 static int lfs_rawmount(lfs_t *lfs, const struct lfs_config *cfg) { argument
4105 int err = lfs_init(lfs, cfg);
4114 if (cycle >= lfs->cfg->block_count/2) {
4195 if (superblock.block_count != lfs->cfg->block_count) {
4197 superblock.block_count, lfs->cfg->block_count);
4202 if (superblock.block_size != lfs->cfg->block_size) {
4204 superblock.block_count, lfs->cfg->block_count);
4235 lfs->free.off = lfs->seed % lfs->cfg->block_count;
4272 if (cycle >= lfs->cfg->block_count/2) {
4357 if (cycle >= lfs->cfg->block_count/2) {
4394 &lfs->pcache, &lfs->rcache, lfs->cfg->block_size,
4413 if (cycle >= lfs->cfg->block_count/2) {
4821 (0x7fffffff & test.size) > lfs->cfg->block_size) {
5001 const struct lfs_config *cfg) { argument
5004 err = lfs_init(lfs, cfg);
5068 static int lfs_rawmigrate(lfs_t *lfs, const struct lfs_config *cfg) { argument
5070 int err = lfs1_mount(lfs, &lfs1, cfg);
5255 .block_size = lfs->cfg->block_size,
5256 .block_count = lfs->cfg->block_count,
5300 #define LFS_LOCK(cfg) cfg->lock(cfg) argument
5301 #define LFS_UNLOCK(cfg) cfg->unlock(cfg) argument
5303 #define LFS_LOCK(cfg) ((void)cfg, 0) argument
5304 #define LFS_UNLOCK(cfg) ((void)cfg) argument
5309 int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { argument
5310 int err = LFS_LOCK(cfg);
5323 (void*)lfs, (void*)cfg, cfg->context,
5324 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
5325 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
5326 cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
5327 cfg->block_cycles, cfg->cache_size, cfg->lookahead_size,
5328 cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer,
5329 cfg->name_max, cfg->file_max, cfg->attr_max);
5331 err = lfs_rawformat(lfs, cfg);
5334 LFS_UNLOCK(cfg);
5339 int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { argument
5340 int err = LFS_LOCK(cfg);
5353 (void*)lfs, (void*)cfg, cfg->context,
5354 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
5355 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
5356 cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
5357 cfg->block_cycles, cfg->cache_size, cfg->lookahead_size,
5358 cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer,
5359 cfg->name_max, cfg->file_max, cfg->attr_max);
5361 err = lfs_rawmount(lfs, cfg);
5364 LFS_UNLOCK(cfg);
5369 int err = LFS_LOCK(lfs->cfg);
5378 LFS_UNLOCK(lfs->cfg);
5384 int err = LFS_LOCK(lfs->cfg);
5393 LFS_UNLOCK(lfs->cfg);
5400 int err = LFS_LOCK(lfs->cfg);
5409 LFS_UNLOCK(lfs->cfg);
5415 int err = LFS_LOCK(lfs->cfg);
5424 LFS_UNLOCK(lfs->cfg);
5430 int err = LFS_LOCK(lfs->cfg);
5440 LFS_UNLOCK(lfs->cfg);
5447 int err = LFS_LOCK(lfs->cfg);
5457 LFS_UNLOCK(lfs->cfg);
5464 int err = LFS_LOCK(lfs->cfg);
5473 LFS_UNLOCK(lfs->cfg);
5480 int err = LFS_LOCK(lfs->cfg);
5491 LFS_UNLOCK(lfs->cfg);
5498 const struct lfs_file_config *cfg) { argument
5499 int err = LFS_LOCK(lfs->cfg);
5506 (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count);
5509 err = lfs_file_rawopencfg(lfs, file, path, flags, cfg);
5512 LFS_UNLOCK(lfs->cfg);
5517 int err = LFS_LOCK(lfs->cfg);
5527 LFS_UNLOCK(lfs->cfg);
5533 int err = LFS_LOCK(lfs->cfg);
5543 LFS_UNLOCK(lfs->cfg);
5550 int err = LFS_LOCK(lfs->cfg);
5561 LFS_UNLOCK(lfs->cfg);
5568 int err = LFS_LOCK(lfs->cfg);
5579 LFS_UNLOCK(lfs->cfg);
5586 int err = LFS_LOCK(lfs->cfg);
5597 LFS_UNLOCK(lfs->cfg);
5603 int err = LFS_LOCK(lfs->cfg);
5614 LFS_UNLOCK(lfs->cfg);
5620 int err = LFS_LOCK(lfs->cfg);
5630 LFS_UNLOCK(lfs->cfg);
5635 int err = LFS_LOCK(lfs->cfg);
5644 LFS_UNLOCK(lfs->cfg);
5649 int err = LFS_LOCK(lfs->cfg);
5659 LFS_UNLOCK(lfs->cfg);
5665 int err = LFS_LOCK(lfs->cfg);
5674 LFS_UNLOCK(lfs->cfg);
5680 int err = LFS_LOCK(lfs->cfg);
5690 LFS_UNLOCK(lfs->cfg);
5695 int err = LFS_LOCK(lfs->cfg);
5704 LFS_UNLOCK(lfs->cfg);
5709 int err = LFS_LOCK(lfs->cfg);
5719 LFS_UNLOCK(lfs->cfg);
5724 int err = LFS_LOCK(lfs->cfg);
5734 LFS_UNLOCK(lfs->cfg);
5739 int err = LFS_LOCK(lfs->cfg);
5748 LFS_UNLOCK(lfs->cfg);
5753 int err = LFS_LOCK(lfs->cfg);
5762 LFS_UNLOCK(lfs->cfg);
5767 int err = LFS_LOCK(lfs->cfg);
5776 LFS_UNLOCK(lfs->cfg);
5781 int err = LFS_LOCK(lfs->cfg);
5791 LFS_UNLOCK(lfs->cfg);
5796 int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { argument
5797 int err = LFS_LOCK(cfg);
5810 (void*)lfs, (void*)cfg, cfg->context,
5811 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog,
5812 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync,
5813 cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count,
5814 cfg->block_cycles, cfg->cache_size, cfg->lookahead_size,
5815 cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer,
5816 cfg->name_max, cfg->file_max, cfg->attr_max);
5818 err = lfs_rawmigrate(lfs, cfg);
5821 LFS_UNLOCK(cfg);