Lines Matching +full:prog +full:- +full:size
5 * SPDX-License-Identifier: Apache-2.0
44 #define LFS_FILEP(fp) (&((struct lfs_file_data *)(fp->filep))->file)
61 #if (CONFIG_FS_LITTLEFS_FC_HEAP_SIZE - 0) <= 0
63 /* Auto-generate heap size from cache size and number of files */
77 static inline void *fc_allocate(size_t size) in fc_allocate() argument
81 ret = k_heap_alloc(&file_cache_heap, size, K_NO_WAIT); in fc_allocate()
93 k_mutex_lock(&fs->mutex, K_FOREVER); in fs_lock()
98 k_mutex_unlock(&fs->mutex); in fs_unlock()
110 return -EIO; in lfs_to_errno()
112 return -EFAULT; in lfs_to_errno()
114 return -ENOENT; in lfs_to_errno()
116 return -EEXIST; in lfs_to_errno()
118 return -ENOTDIR; in lfs_to_errno()
120 return -EISDIR; in lfs_to_errno()
122 return -ENOTEMPTY; in lfs_to_errno()
124 return -EBADF; in lfs_to_errno()
126 return -EFBIG; in lfs_to_errno()
128 return -EINVAL; in lfs_to_errno()
130 return -ENOSPC; in lfs_to_errno()
132 return -ENOMEM; in lfs_to_errno()
144 case -EIO: /* Error during device operation */ in errno_to_lfs()
146 case -EFAULT: /* Corrupted */ in errno_to_lfs()
148 case -ENOENT: /* No directory entry */ in errno_to_lfs()
150 case -EEXIST: /* Entry already exists */ in errno_to_lfs()
152 case -ENOTDIR: /* Entry is not a dir */ in errno_to_lfs()
154 case -EISDIR: /* Entry is a dir */ in errno_to_lfs()
156 case -ENOTEMPTY: /* Dir is not empty */ in errno_to_lfs()
158 case -EBADF: /* Bad file number */ in errno_to_lfs()
160 case -EFBIG: /* File too large */ in errno_to_lfs()
162 case -EINVAL: /* Invalid parameter */ in errno_to_lfs()
164 case -ENOSPC: /* No space left on device */ in errno_to_lfs()
166 case -ENOMEM: /* No more memory available */ in errno_to_lfs()
175 lfs_off_t off, void *buffer, lfs_size_t size) in lfs_api_read() argument
177 const struct flash_area *fa = c->context; in lfs_api_read()
178 size_t offset = block * c->block_size + off; in lfs_api_read()
180 int rc = flash_area_read(fa, offset, buffer, size); in lfs_api_read()
186 lfs_off_t off, const void *buffer, lfs_size_t size) in lfs_api_prog() argument
188 const struct flash_area *fa = c->context; in lfs_api_prog()
189 size_t offset = block * c->block_size + off; in lfs_api_prog()
191 int rc = flash_area_write(fa, offset, buffer, size); in lfs_api_prog()
198 const struct flash_area *fa = c->context; in lfs_api_erase()
199 size_t offset = block * c->block_size; in lfs_api_erase()
201 int rc = flash_area_flatten(fa, offset, c->block_size); in lfs_api_erase()
209 lfs_off_t off, void *buffer, lfs_size_t size) in lfs_api_read_blk() argument
211 const char *disk = c->context; in lfs_api_read_blk()
213 size / c->block_size); in lfs_api_read_blk()
219 lfs_off_t off, const void *buffer, lfs_size_t size) in lfs_api_prog_blk() argument
221 const char *disk = c->context; in lfs_api_prog_blk()
222 int rc = disk_access_write(disk, buffer, block, size / c->block_size); in lfs_api_prog_blk()
229 const char *disk = c->context; in lfs_api_sync_blk()
236 lfs_off_t off, void *buffer, lfs_size_t size) in lfs_api_read_blk() argument
242 lfs_off_t off, const void *buffer, lfs_size_t size) in lfs_api_prog_blk() argument
264 struct lfs_file_data *fdp = fp->filep; in release_file_data()
266 if (fdp->config.buffer) { in release_file_data()
267 fc_release(fdp->cache_block); in release_file_data()
270 k_mem_slab_free(&file_data_pool, fp->filep); in release_file_data()
271 fp->filep = NULL; in release_file_data()
292 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_open()
293 struct lfs *lfs = &fs->lfs; in littlefs_open()
295 int ret = k_mem_slab_alloc(&file_data_pool, &fp->filep, K_NO_WAIT); in littlefs_open()
301 struct lfs_file_data *fdp = fp->filep; in littlefs_open()
305 fdp->cache_block = fc_allocate(lfs->cfg->cache_size); in littlefs_open()
306 if (fdp->cache_block == NULL) { in littlefs_open()
307 ret = -ENOMEM; in littlefs_open()
311 fdp->config.buffer = fdp->cache_block; in littlefs_open()
312 path = fs_impl_strip_prefix(path, fp->mp); in littlefs_open()
316 ret = lfs_file_opencfg(&fs->lfs, &fdp->file, in littlefs_open()
317 path, flags, &fdp->config); in littlefs_open()
330 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_close()
334 int ret = lfs_file_close(&fs->lfs, LFS_FILEP(fp)); in littlefs_close()
345 struct fs_littlefs *fs = mountp->fs_data; in littlefs_unlink()
351 int ret = lfs_remove(&fs->lfs, path); in littlefs_unlink()
360 struct fs_littlefs *fs = mountp->fs_data; in littlefs_rename()
367 int ret = lfs_rename(&fs->lfs, from, to); in littlefs_rename()
375 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_read()
379 ssize_t ret = lfs_file_read(&fs->lfs, LFS_FILEP(fp), ptr, len); in littlefs_read()
387 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_write()
391 ssize_t ret = lfs_file_write(&fs->lfs, LFS_FILEP(fp), ptr, len); in littlefs_write()
403 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_seek()
407 off_t ret = lfs_file_seek(&fs->lfs, LFS_FILEP(fp), off, whence); in littlefs_seek()
420 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_tell()
424 off_t ret = lfs_file_tell(&fs->lfs, LFS_FILEP(fp)); in littlefs_tell()
432 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_truncate()
436 int ret = lfs_file_truncate(&fs->lfs, LFS_FILEP(fp), length); in littlefs_truncate()
444 struct fs_littlefs *fs = fp->mp->fs_data; in littlefs_sync()
448 int ret = lfs_file_sync(&fs->lfs, LFS_FILEP(fp)); in littlefs_sync()
456 struct fs_littlefs *fs = mountp->fs_data; in littlefs_mkdir()
461 int ret = lfs_mkdir(&fs->lfs, path); in littlefs_mkdir()
469 struct fs_littlefs *fs = dp->mp->fs_data; in littlefs_opendir()
471 if (k_mem_slab_alloc(&lfs_dir_pool, &dp->dirp, K_NO_WAIT) != 0) { in littlefs_opendir()
472 return -ENOMEM; in littlefs_opendir()
475 memset(dp->dirp, 0, sizeof(struct lfs_dir)); in littlefs_opendir()
477 path = fs_impl_strip_prefix(path, dp->mp); in littlefs_opendir()
481 int ret = lfs_dir_open(&fs->lfs, dp->dirp, path); in littlefs_opendir()
486 k_mem_slab_free(&lfs_dir_pool, dp->dirp); in littlefs_opendir()
494 entry->type = ((info->type == LFS_TYPE_DIR) ? in info_to_dirent()
496 entry->size = info->size; in info_to_dirent()
497 strncpy(entry->name, info->name, sizeof(entry->name)); in info_to_dirent()
498 entry->name[sizeof(entry->name) - 1] = '\0'; in info_to_dirent()
503 struct fs_littlefs *fs = dp->mp->fs_data; in littlefs_readdir()
508 int ret = lfs_dir_read(&fs->lfs, dp->dirp, &info); in littlefs_readdir()
516 entry->name[0] = 0; in littlefs_readdir()
524 struct fs_littlefs *fs = dp->mp->fs_data; in littlefs_closedir()
528 int ret = lfs_dir_close(&fs->lfs, dp->dirp); in littlefs_closedir()
532 k_mem_slab_free(&lfs_dir_pool, dp->dirp); in littlefs_closedir()
540 struct fs_littlefs *fs = mountp->fs_data; in littlefs_stat()
547 int ret = lfs_stat(&fs->lfs, path, &info); in littlefs_stat()
562 struct fs_littlefs *fs = mountp->fs_data; in littlefs_statvfs()
563 struct lfs *lfs = &fs->lfs; in littlefs_statvfs()
565 stat->f_bsize = lfs->cfg->prog_size; in littlefs_statvfs()
566 stat->f_frsize = lfs->cfg->block_size; in littlefs_statvfs()
567 stat->f_blocks = lfs->cfg->block_count; in littlefs_statvfs()
578 stat->f_bfree = stat->f_blocks - ret; in littlefs_statvfs()
588 /* Return maximum page size in a flash area. There's no flash_area
600 size_t info_start = info->start_offset; in get_page_cb()
601 size_t info_end = info_start + info->size - 1U; in get_page_cb()
602 size_t area_start = ctx->area->fa_off; in get_page_cb()
603 size_t area_end = area_start + ctx->area->fa_size - 1U; in get_page_cb()
613 if (info->size > ctx->max_size) { in get_page_cb()
614 ctx->max_size = info->size; in get_page_cb()
622 * largest page size we see. This works as long as the partition is
623 * aligned so that erasing with this size is supported throughout the
653 const struct flash_area **fap = (const struct flash_area **)&fs->backend; in littlefs_flash_init()
661 return -ENODEV; in littlefs_flash_init()
665 (uint32_t)(*fap)->fa_off, (uint32_t)(*fap)->fa_size); in littlefs_flash_init()
670 (*fap)->fa_dev->name); in littlefs_flash_init()
671 return -ENODEV; in littlefs_flash_init()
674 fs->backend = (void *) *fap; in littlefs_flash_init()
686 return -ENOTSUP; in littlefs_init_backend()
691 fs->backend = dev_id; in littlefs_init_backend()
692 ret = disk_access_init((char *) fs->backend); in littlefs_init_backend()
722 struct lfs_config *lcp = &fs->cfg; in littlefs_init_cfg()
724 lfs_size_t read_size = lcp->read_size; in littlefs_init_cfg()
730 lfs_size_t prog_size = lcp->prog_size; in littlefs_init_cfg()
736 /* Yes, you can override block size. */ in littlefs_init_cfg()
737 lfs_size_t block_size = lcp->block_size; in littlefs_init_cfg()
742 return -ENOTSUP; in littlefs_init_cfg()
748 int ret = disk_access_ioctl((char *) fs->backend, in littlefs_init_cfg()
752 LOG_ERR("Unable to get sector size"); in littlefs_init_cfg()
760 block_size = get_block_size((struct flash_area *)fs->backend); in littlefs_init_cfg()
767 return -EINVAL; in littlefs_init_cfg()
770 int32_t block_cycles = lcp->block_cycles; in littlefs_init_cfg()
777 block_cycles = -1; in littlefs_init_cfg()
780 lfs_size_t cache_size = lcp->cache_size; in littlefs_init_cfg()
786 lfs_size_t lookahead_size = lcp->lookahead_size; in littlefs_init_cfg()
793 uint32_t disk_version = lcp->disk_version; in littlefs_init_cfg()
805 int ret = disk_access_ioctl((char *) fs->backend, in littlefs_init_cfg()
810 return -EINVAL; in littlefs_init_cfg()
812 LOG_INF("FS at %s: is %u 0x%x-byte blocks with %u cycle", in littlefs_init_cfg()
813 (char *) fs->backend, block_count, block_size, in littlefs_init_cfg()
820 block_count = ((struct flash_area *)fs->backend)->fa_size in littlefs_init_cfg()
823 flash_area_get_device((struct flash_area *)fs->backend); in littlefs_init_cfg()
824 LOG_INF("FS at %s:0x%x is %u 0x%x-byte blocks with %u cycle", in littlefs_init_cfg()
825 dev->name, in littlefs_init_cfg()
826 (uint32_t)((struct flash_area *)fs->backend)->fa_off, in littlefs_init_cfg()
840 "erase size must be multiple of write size"); in littlefs_init_cfg()
842 "cache size incompatible with block size"); in littlefs_init_cfg()
844 lcp->context = fs->backend; in littlefs_init_cfg()
850 lcp->read = lfs_api_read_blk; in littlefs_init_cfg()
851 lcp->prog = lfs_api_prog_blk; in littlefs_init_cfg()
852 lcp->erase = lfs_api_erase_blk; in littlefs_init_cfg()
854 lcp->read_size = block_size; in littlefs_init_cfg()
855 lcp->prog_size = block_size; in littlefs_init_cfg()
858 LOG_ERR("Configured cache size is too small: %d < %d", cache_size, in littlefs_init_cfg()
860 return -ENOMEM; in littlefs_init_cfg()
862 lcp->cache_size = new_cache_size; in littlefs_init_cfg()
865 LOG_ERR("Configured lookahead size is too small: %d < %d", in littlefs_init_cfg()
867 return -ENOMEM; in littlefs_init_cfg()
869 lcp->lookahead_size = new_lookahead_size; in littlefs_init_cfg()
871 lcp->sync = lfs_api_sync_blk; in littlefs_init_cfg()
874 lcp->read_size, lcp->prog_size, lcp->cache_size, in littlefs_init_cfg()
875 lcp->lookahead_size); in littlefs_init_cfg()
877 __ASSERT((((struct flash_area *)fs->backend)->fa_size % in littlefs_init_cfg()
879 "partition size must be multiple of block size"); in littlefs_init_cfg()
881 lcp->read = lfs_api_read; in littlefs_init_cfg()
882 lcp->prog = lfs_api_prog; in littlefs_init_cfg()
883 lcp->erase = lfs_api_erase; in littlefs_init_cfg()
886 lcp->read_size = read_size; in littlefs_init_cfg()
887 lcp->prog_size = prog_size; in littlefs_init_cfg()
888 lcp->cache_size = cache_size; in littlefs_init_cfg()
889 lcp->lookahead_size = lookahead_size; in littlefs_init_cfg()
890 lcp->sync = lfs_api_sync; in littlefs_init_cfg()
894 lcp->disk_version = disk_version; in littlefs_init_cfg()
900 lcp->block_size = block_size; in littlefs_init_cfg()
901 lcp->block_count = block_count; in littlefs_init_cfg()
902 lcp->block_cycles = block_cycles; in littlefs_init_cfg()
914 if (fs->backend) { in littlefs_init_fs()
915 return -EBUSY; in littlefs_init_fs()
933 struct fs_littlefs *fs = mountp->fs_data; in littlefs_mount()
936 k_mutex_init(&fs->mutex); in littlefs_mount()
939 ret = littlefs_init_fs(fs, mountp->storage_dev, mountp->flags); in littlefs_mount()
945 ret = lfs_mount(&fs->lfs, &fs->cfg); in littlefs_mount()
947 (mountp->flags & FS_MOUNT_FLAG_NO_FORMAT) == 0) { in littlefs_mount()
948 if ((mountp->flags & FS_MOUNT_FLAG_READ_ONLY) == 0) { in littlefs_mount()
950 ret = lfs_format(&fs->lfs, &fs->cfg); in littlefs_mount()
957 LOG_ERR("can not format read-only system"); in littlefs_mount()
958 ret = -EROFS; in littlefs_mount()
962 ret = lfs_mount(&fs->lfs, &fs->cfg); in littlefs_mount()
973 LOG_INF("%s mounted", mountp->mnt_point); in littlefs_mount()
977 fs->backend = NULL; in littlefs_mount()
998 fs->backend = NULL; in littlefs_mkfs()
1001 k_mutex_init(&fs->mutex); in littlefs_mkfs()
1009 ret = lfs_format(&fs->lfs, &fs->cfg); in littlefs_mkfs()
1016 fs->backend = NULL; in littlefs_mkfs()
1025 struct fs_littlefs *fs = mountp->fs_data; in littlefs_unmount()
1029 lfs_unmount(&fs->lfs); in littlefs_unmount()
1032 if (!littlefs_on_blkdev(mountp->flags)) { in littlefs_unmount()
1033 flash_area_close(fs->backend); in littlefs_unmount()
1037 fs->backend = NULL; in littlefs_unmount()
1040 LOG_INF("%s unmounted", mountp->mnt_point); in littlefs_unmount()
1123 LOG_INF("littlefs partition at %s", mp->mnt_point); in DT_INST_FOREACH_STATUS_OKAY()
1124 if ((mp->flags & FS_MOUNT_FLAG_AUTOMOUNT) != 0) { in DT_INST_FOREACH_STATUS_OKAY()
1129 mp->mnt_point, rc); in DT_INST_FOREACH_STATUS_OKAY()
1132 mp->mnt_point); in DT_INST_FOREACH_STATUS_OKAY()