The cmd_write and cmd_ctunc have been opening/creating file for
read/write operation.
The commit changes cmd_write to open/create file for write only,
and cmd_trunc to only open file for write.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The cmd_read function uses fs_open with FS_O_CREATE | FS_O_RDWR flags
to open file it will only read; the flags has been changed
to FS_O_READ.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
llvm 11 doesn't like having preprocessor directives in the expansion
of a macro used as a preprocessor conditional expression.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Fixes problem when fs_opendir invoked on fs_dir_t object,
which is already holding information on opened directory,
overwrites references to other memory objects within
the fs_dir_t object causing resource leak.
If fs_opendir is invoked on already used fs_dir_t object,
it will return
-EBUSY.
Note: The change requires that all fs_dir_t objects should be
initialized to 0.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
The commit adds initializations of fs_dir_t variables in preparation
for fs_opendir function change that will require fs_dir_t object, passed
to the function, to be initialized before first usage.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
The mem_pool Kconfig API is deprecated as allocation now uses a k_heap.
Update to allocate a heap with the same amount of memory as was
defaulted with mem_pool customization.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Originally the file cache used a mem_pool, but that data structure has
been deprecated and replaced by a heap that includes metadata in the
heap area. As a result attempts to allocate all blocks will fail
because some of the reservation intended for cache data is now holding
metadata instead.
It's not immediately clear how to adjust the required heap size to
support this metadata as it depends on heap chunk units and data
structures that are not visible to the application. Experimentally a
value of 24 bytes works, while smaller values do not.
Further the previous Kconfig API to configure the allocation pool is
completely inappropriate with the new heap data structure which has
such different behavior.
So: Deprecate the old Kconfig API. Add a new Kconfig option to
directly control the cache size. Infer a default cache size that
works with the old mem_pool parameters assuming a per-block overhead.
But to avoid wasted memory use the heap allocation only when the
application customizes the size, and use a slab in other cases.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Fixes problem when fs_open invoked on fs_file_t object, which is already
holding information on opened file, overwrites references to other
memory objects within the fs_file_t object causing resource leak.
If fs_open is invoked on already used fs_file_t object, it will return
-EBUSY.
Note: The change requires that all fs_file_t objects should be
initialized to 0.
Fixes: #29478
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit adds initializations of fs_file_t variables in preparation
for fs_open function change that will require fs_file_t object, passed
to the function, to be initialized before first usage.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit adds initializations of fs_file_t variables in preparation
for fs_open function change that will require fs_file_t object, passed
to the function, to be initialized before first usage.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Make sector size used by flash disk configurable and expose new disk and
fatfs configurations to Kconfig.
Signed-off-by: Markus Fuchs <markus.fuchs@de.sauter-bc.com>
Use the devicetree filesystem bindings to populate an fs_mount_t
object that is preconfigured for a particular set of file system
properties on a specified partition.
At this time the mount point data is accessed by reference using the
partition's devicetree node identifier.
Note: While a file system can register itself before its devices
are available, it cannot do the automount. In this commit the
initialization priority is increased to compensate, but that's not
a long-term solution.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.
Almost all of this is straightforward swapping of one alloc/free call
for another. In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.
Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Mark all k_mem_pool APIs deprecated for future code. Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.
Fixes#24358
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
The FCB has been strongly tied to 0xff erased flash devices and this
commit adds support for other erase values.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Adds various tests for mounting ELM FAT FS with FS_MOUNT_FLAG_NO_FORMAT
and FS_MOUNT_FLAG_READ_ONLY, and operations on read-only mounted
file system.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Adds various tests for mounting LittleFS with FS_MOUNT_FLAG_NO_FORMAT
and FS_MOUNT_FLAG_READ_ONLY, and operations on read-only mounted
file system.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The flags field has been added to fs_mount_t structure, accompanied
with two new flags:
FS_MOUNT_FLAG_READ_ONLY -- mount fs as read only
FS_MOUNT_FLAG_NO_FORMAT -- do not format volume when system not found
Code supporting the flags has been added to FS layer and drivers for
LittleFS and FAT FS.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit adds FS_FATFS_READ_ONLY Kconfig option; the option, when
selected, excludes write supporting code within ELM FAT driver.
When write support to FAT FS volumes is not desired, this option may be
selected to slightly reduce code size.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit adds FS_FAFTFS_MKFS Kconfig option; the option, y by default,
allows to include mkfs supporting code, within fs_mount callback,
for ELM FAT file system driver.
When formatting of FAT FS volumes is not desired, this option may be
deselected to slightly reduce code size.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit changes run-time checks of file system driver's callbacks
pointers, against null, optional by replacing `if` with `CHECKIF` macro,
which means that they can be removed from compilation with Kconfig
option CONFIG_NO_RUNTIME_CHECKS.
Additionally the commit allows the same checks to fail hard, with
assertion, when CONFIG_ASSERT_ON_ERRORS option is selected.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit changes error handling by fs_unmount; the function will
return -EINVAL if mount point, described by mp, is not mounted or
-ENNOTSUP when unmounting is not supported by the driver; in the second
case it will also log error.
Additionally to the above changes, checks for correct mnt_path and
mnt_path, within fs_unmount, have been removed as they are not needed;
only the fs_mount_t->fs pointer is needed to decide whether system is
mounted or not.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The commit moves fs_mount parameter verification above mutex lock.
The list of mount points is now checked before attempting to obtain
file system API pointer.
All modifications to mount point data structure, given as a parameter
to the fs_mount, are only applied after every other operation needed
have completed successfully, immediately before adding the mount point
to the list of mount points.
The fs_mount will a warning when mounted file system does not support
unmount.
When a file system does not provide mount function, the -ENOTSUP error
will be returned instead of -EINVAL.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The struct fs_file_system_t is only useful when defining file system
drivers and is not required for typical application development,
that is why it has been moved to separate file fs_sys.h.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Simple change that makes fs_seek and fs_tell return -ENOTSUP when
file system does not implement the seek/tell.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The second argument of this foonction is a bool, so passing 0 and 1
is incorrect.
Coccinelle script:
@@
expression e;
@@
flash_write_protection_set(e,
(
- 0
+ false
|
- 1
+ true
)
)
Signed-off-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@nordicsemi.no>
Zephyr allows an application to register additional file systems,
which may have maximum filename lengths different from the in-tree
FatFs and littlefs options. Provide a Kconfig variable that allows
the default inference to be overridden.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The documentation claims that Zephyr supports external file system
implementations, and there's no reason not to do so. Rework the API
to allow this.
Note that the file system type cannot legally be an enum anymore,
since we need to support file system types that don't have an
identifier assigned in that enum. Rely on the implicit conversion of
enum values to int to preserve backwards compatibility.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Expose the exFAT support option to Kconfig, so developer can
enable/disable the exFAT support on FatFs through Kconfig, no need to
touch ffconf.h.
Signed-off-by: Jui-Chou Chung <jui-chou.chung@nordicsemi.no>
When FAT FS option is enabled, then the FAT FS sub-menu will appear
next to it, instead of appearing far down the list.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
The fs_open has been extended with support for open flags.
Currently supported flags are:
FS_O_READ -- open for read
FS_O_WRITE -- open for write
FS_O_CREATE -- create file if it does not exist
FS_O_APPEND -- move to the end of file before each write
The FAT FS and LittleFS front-ends within the Zephyr has also been
modified to utilize the flags.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Attempt to perform fs_read, fs_write, fs_seek, fs_tell, fs_truncate
and fs_sync on file that has been closed, prior to attempt, would cause
NULL pointer dereference.
With this fix, such operations would instead return -EBADF.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
If fs_close gets invoked on closed file (e.g. double close) it would
cause NULL dereference and system crash. Instead now it will just
return with success, as the file is already closed anyway.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
nvs_gc does not verify the crc8 of close_ate before using
close_ate.offset. This means that close_ate.offset could contain an
offset that points beyond valid ate's in the sector. For example, there
might be a valid ate at offset 0x100 but close_ate.offset is 0x200.
If that is the case that value will not be moved and so it will be lost.
Solve this by refactoring the recovery loop from nvs_prev_ate into
nvs_recover_last_ate and use that function in nvs_gc if a corrupt
close_ate is found.
The crc8 of gc_ate is not checked before trying to find another ate
with the same id. If there are no valid ate with that id in the whole
fs the inner while(1)-loop will never stop since the break condition
includes a check for a correct crc8.
Solve this by skipping gc_ate's with an invalid crc8.
Fixes#26407
Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
fatfs_open and fatfs_opendir fail to free reserved memory on error
which may lead to memory exhaustion, when too many file/dir open errors
are caused, and will cause all subsequent open attempts to fail with
ENOMEM error.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Pointer to flash_parameters have been added to nvs_fs structure and it
is no longer needed to store write_block_size within the nvs_fs.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Initialize LittleFS at POST_KERNEL and not at APPLICATION stage.
When using LittleFS as settings backend for OpenThread, LittleFS needs
to be available when net_init is performed.
Arguably, FS is an OS kernel component that should be ready when
applications are starting.
Possibly, the same change should be applied to FAT fs as well.
Signed-off-by: Markus Becker <markus.becker@tridonic.com>
The current code truncates the size_t block size to a u8_t, which
causes a 256 or 512 byte block size to be truncated to zero and
passing the size check.
Check as a size_t then truncate once the check passes.
Signed-off-by: Michael Hope <mlhx@google.com>
Convert with a combo of scripts and by hand fixups:
git grep -l DT_FLASH_AREA_.*_ID | \
xargs sed -i -r 's/DT_FLASH_AREA_(.*)_ID/FLASH_AREA_ID(\L\1)/'
git grep -l DT_FLASH_AREA_.*_OFFSET | \
xargs sed -i -r 's/DT_FLASH_AREA_(.*)_OFFSET/FLASH_AREA_OFFSET(\L\1)/'
git grep -l DT_FLASH_AREA_.*_SIZE | \
xargs sed -i -r 's/DT_FLASH_AREA_(.*)_SIZE/FLASH_AREA_SIZE(\L\1)/'
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>