Commit graph

401 commits

Author SHA1 Message Date
Keith Packard
f50ee8c1d3 fs/ext2: Missing error check in ext2_inode_remove_blocks
Don't assume that get_level_offsets will succeed.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-17 16:06:21 +02:00
Alberto Escolar Piedras
da6742b776 subsys/fs/fuse: Fix adding missing stddef header
Instead of relaying on stddef.h being included by other headers
let's include it explicitly, following a report of it being
missing for Ubuntu 22.04 (glibc 2.35)

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-05-28 01:48:13 +02:00
Yonas Alizadeh
440de0dde0 fs: nvs: fix invalid block compare when data CRC is enabled
When nvs_write is called, the nvs_flash_block_cmp is used to check if
the new data to be written matches the data already on flash. This check
always fail when CONFIG_NVS_DATA_CRC is enabled, caused by the
NVS_DATA_CRC_SIZE being added to the len parameter. The pointer to the
new data does not already have the CRC part added, while the data on
flash does, and the size to be compared includes CRC section.
By removing the addition of NVS_DATA_CRC_SIZE to the compare size, only
the data without CRC is compared, which will make the compare work in
both cases.

Signed-off-by: Yonas Alizadeh <yonas.alizadeh@alfalaval.com>
2025-05-26 09:19:54 +02:00
Xudong Zheng
151ca3a31f fs: littlefs: define default disk version in Kconfig
This makes it possible to set the disk version when Devicetree is not
used for configuration.

Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com>
2025-05-20 15:24:00 +02:00
Riadh Ghaddab
5c38c58f0c zms: optimize cache for settings subsystem
Settings subsystem is storing the name ID and the linked list node ID
with only one bit difference at BIT(0).
Settings subsystem is also storing the name ID and the data ID in two
different ZMS entries at an exact offset of ZMS_DATA_ID_OFFSET.
Using the regular lookup function could result in many cache misses.

Therefore, to assure the least number of collisions in the lookup cache,
the BIT(0) of the hash indicates whether the given ZMS ID represents a
linked list entry or not, the BIT(1) indicates whether the ZMS ID is a
name or data and the remaining bits of the hash are set to a truncated
part of the original hash generated by Settings.

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-05-15 17:53:26 +02:00
Riadh Ghaddab
42b9b5a9d7 zms: remove non needed lookup cache before writing
When the CONFIG_ZMS_NO_DOUBLE_WRITE is not enabled there is no need to
search in the cache for matching ID

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-05-15 17:53:26 +02:00
Riadh Ghaddab
2eba2e9c9c zms: add more robustiness in extreme cases
When power cuts during a GC operation, the sector is erased again in the
next reboot cycle and the cycle_cnt of the empty ATE is incremented.
If the same power cut happens 255 times in a row, the empty ATE cycle_cnt
will become equal to the close ATE which causes a memory corruption.
Fix this by checking the close ATE cycle_cnt before incrementing the
empty ATE cycle_cnt.

Fixes: #84874
Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-04-16 20:36:49 +02:00
Gerhard Jörges
cbfa49f378 fs: shell: fix maybe-uninitialized warning
`read` may have been used uninitialized.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2025-04-14 11:49:28 +02:00
Riadh Ghaddab
15cbe9fd18 zms: fix the detection of gc_done ATE
Previously, when detecting the GC_done ATE the gc_done_marker boolean
variable was not set.
Fix this by setting it to true if the GC_done ATE is found.

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-04-08 10:48:17 +02:00
Kiara Navarro
9207a1bcd7 fs: update module logging registration
All modules registered in fs subsystem uses:

LOG_MODULE_REGISTER(<module>, <log level>)

Lets update fs to follow same logic.

Signed-off-by: Kiara Navarro <knavarro@paltatech.com>
2025-03-27 03:50:22 +01:00
Martin Stumpf
d7d6038cfb fs: shell: Refactoring
- Run reformat
- Fix ifs not containing bool expressions (coding guideline 85)
- Fix error codes
- Fix missing error handling in `cmd_read`
- Fix incorrect handling of `fs_read` in `cmd_read_test`

Signed-off-by: Martin Stumpf <finomnis@gmail.com>
2025-03-17 02:20:40 +01:00
Carlo Kirchmeier
1ea0267a31 fs: enable fstab devicetree integration for fatfs
In order to use fstab with fatfs in addition to
littlefs a new driver fstab,fatfs was introduced
containing the required logic to detect and if
needed automount fatfs devices specified in fstab.
Additionally as the partition phandle is not needed
by fatfs and currently is specific to littlefs it
was moved from the common dts binding into the
littlefs binding.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Co-authored-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
Co-authored-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2025-03-15 13:07:40 +01:00
Andrej Butok
8473928db4 zms: fix the zms_mount() sector_size check
Adds the return -EINVAL, if the fix zms_mount() sector_size
check is failed.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2025-03-12 02:29:31 +01:00
Alberto Escolar Piedras
ac24d2277e native FUSE FS access: Support any libC and fix random crashes
Split the fuse FS driver into 2 parts: A top built in the embedded side,
with the embedded libC, and a bottom built in the runner side with the
host libC.
The error returns are converted to match the host libC.

Also, before the host FUSE thread, which is asynchronous to Zephyr was
calling directly into the Zephyr filesystem code, which resulted quite
often if catastrophic failures or corruption of the Zephyr state.
This is now fixed by having the FUSE thread queue requests to a Zephyr
thread, which will be handled in the embedded side in a coherent way.
This adds a slightly noticeable overhead, but the performance is still
acceptable.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-08 15:26:29 +01:00
Riadh Ghaddab
f020720a80 fs: zms: fix Copyright notice
Add missing Copyright from derived files and fix the Copyright year for
some files to keep the original Copyright notice

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-03-04 12:17:02 +00:00
Jordan Yates
76c526a035 fs: nvs: move FLASH_PAGE_LAYOUT to depends on
`FLASH_PAGE_LAYOUT` has a hardware dependency on `FLASH_HAS_PAGE_LAYOUT`
which is not present for all boards. Forcing this symbol to `y` when
the hardware doesn't support it results in build errors at the Kconfig
stage.

`FLASH_PAGE_LAYOUT` is enabled by default when `FLASH_HAS_PAGE_LAYOUT`
is true, so this change will not require any user changes.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-02-27 09:07:56 +00:00
Riadh Ghaddab
5f7cda5e06 fs: zms: multiple style fixes from previous PR review
This resolves some addressed comments in this PR zephyrproject-rtos#77930
as well as this PR zephyrproject-rtos#80407

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-02-21 11:29:50 +00:00
Carlo Kirchmeier
ae96ccc3d7 fs: enable custom mount points for fatfs
Introduce two new kconfig options in order
to be able to define custom named fatfs
mount points. If activated replace the static
FF_VOLUME_STRS approach with the runtime
generated VolumeStr array containing those
mount points.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
2025-02-13 16:41:34 +01:00
Martin Stumpf
8c82d00b6f fs: shell: Add cp command
Creates a copy of a given file.

Signed-off-by: Martin Stumpf <martin.stumpf@vected.de>
2025-02-08 08:14:16 +01:00
Benjamin Cabé
7c6d3a6f93 fs: ext2: Fix potential integer overflow in disk access size calculation
Cast sector_count and sector_size to uint64_t to prevent potential
integer overflow when calculating total device size in
disk_access_device_size().

Fixes Coverity issue CID-322647

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-30 16:20:58 +01:00
Jordan Yates
946f6b5c2e fs: allow enabling filesystems with FILE_SYSTEM_LIB_LINK
Update the Kconfig configuration to allow enabling the underlying
filesystems (e.g. exFAT), with only `FILE_SYSTEM_LIB_LINK` enabled.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-01-21 15:13:05 +01:00
Jordan Yates
c26656c83f fs: ext2: fix uninitialized variable
The compiler is unaware of the `block_size > 0` precondition, so it
outputs warnings of uninitialized `reclen`. Explicitly initialize the
variable to suppress this.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-01-21 15:13:05 +01:00
Jordan Yates
cd311380dd fs: ext2: update CONFIG_MAX_FILES name
Add the `EXT2` prefix to `config MAX_FILES` to more appropriately
namespace the symbol.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-01-21 15:13:05 +01:00
Dominik Ermel
ac5cdcdb8a fs/littlefs: Log error code on failed flash_area_open
Log error code to make it easier to investigate problems.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2025-01-18 12:39:53 +01:00
Chen Shu
5a5f05ba4e fs: ext2: Fix nbytes_to_read calculation in ext2_inode_read()
Fix incorrect nbytes_to_read calculation in ext2_inode_read() function.
Previously nbytes_to_read was decremented by read value which caused
incorrect calculation of bytes to read in subsequent iterations.
Now nbytes_to_read is decremented by to_read value which represents
the actual number of bytes read in current iteration.

This fixes potential data corruption issues when reading files from
ext2 filesystem.

Signed-off-by: Chen Shu <751541594@qq.com>
2025-01-15 11:51:10 +01:00
Chris Friedt
ec7d272979 fs: allow mounting filesystems at /
Previously, filesystems could not be mounted at '/' because
mount points were restricted to being at least 2 characters.

Since '/' corresponds to the standard POSIX root filesystem
location, reduce the minimum length of a mount point to
1 character.

With that, we can mount a POSIX root filesystem.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-10 04:13:01 +01:00
Djordje Nedic
30bac038fa fs: littlefs: Fix lookahead buffer sizing
The lookahead buffer is a bitmap containing info on free blocks and does
not have a minimum size or an alignment requirement.

This fixes the arbitrary 4 * block_size requirement for block devices
and fixes Kconfig documentation to remove a reference to nonexistent
8 byte alignment requirement.

Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
2025-01-09 04:04:16 +01:00
Djordje Nedic
2a206a07b3 fs: littlefs: Improve block device cache size
Instead of picking a set of safe block multiple sized values for caches,
round down to the nearest block multiple, increasing static buffer usage
determined by Kconfig variables.

Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
2025-01-09 04:04:16 +01:00
Xudong Zheng
6231a9ee19 fs: shell: Add configuration option for mount subcommand
The mount subcommand requires the heap to be present. Excluding it reduces
flash and RAM usage.

Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com>
2024-12-29 05:49:58 +01:00
Cory Andrew Mayer
58514c291c fs: nvs: Add recovery path for corrupted NVS
When all sectors have non-zero data, NVS would fail to init.
Add recovery path option to erase the all sectors and reinitialize.
This could occur due to non-empty sectors, or corrupted data.

Signed-off-by: Cory Andrew Mayer <corymayer@meta.com>
2024-12-23 09:15:48 +01:00
Riadh Ghaddab
e0f0256538 zms: optimize write function by skipping unnecessary reads
when performing a write ZMS checks if the data exists in the storage to
avoid double writing the same data and save some memory cycle life time.
However this downgrades the write performance.
Enable this feature only when CONFIG_ZMS_NO_DOUBLE_WRITE is enabled.

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2024-12-19 19:55:30 +01:00
Mikhail Siomin
a5a955d024 fs: littlefs: add littlefs disk version selection
Add the ability to select littlefs disk version
to maintain backward compatibility
with existing littlefs
with the same major disk version.

Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
2024-12-17 20:55:51 +01:00
Tomi Fontanilles
9ef6788bd9 fs: zms: fix format string
Use %zu for size_t.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-12-17 11:34:42 +00:00
Djordje Nedic
2750492e86 fs: littlefs: Fix cache and lookahead size checks
This fixes an issue where wrong values were checked against block device
defaults. Kconfig values are used when no filesystem config values are
provided, and the buffers are sized according to the Kconfig values,
but the checks were only performed against filesystem config variables.

Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
2024-12-16 20:49:21 +01:00
DEVER Emiel
336c650646 fs: ext2: Fix ext2 read buffer overflow
Keep track of the amount of bytes read so no buffer overflow occurs.

Signed-off-by: DEVER Emiel <emiel.dever@psicontrol.com>
2024-12-16 10:52:29 +01:00
Chris Desjardins
862af5e903 fs: Fix null pointer exception caused by async fs_unmount
The mp pointer is in fs_file_t and fs_dir_t so if the fs pointer is made
NULL then subsequent file I/O operations will cause a NULL pointer
exception. Removing the mount point from the list is threadsafe and
should be sufficient.

Signed-off-by: Chris Desjardins <chris@arch-embedded.com>
2024-11-07 18:06:58 -06:00
Daniel DeGrasse
07a8e3253a drivers: disk: mmc_subsys: remove CONFIG_MMC_VOLUME_NAME
Remove CONFIG_MMC_VOLUME_NAME, and set the disk name based on the
``disk-name`` property. This aligns with other disk drivers, and allows
for multiple instances of the mmc_subsys disk driver to be registered.

Add disk-name properties for all in tree definitions for the
mmc-subsys disk driver, and change all in tree usage of the disk name

Fixes #75004

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-11-05 15:25:10 -06:00
Daniel DeGrasse
a1dc0b8b3e drivers: disk: sdmmc_subsys: remove CONFIG_SDMMC_VOLUME_NAME
Remove CONFIG_SDMMC_VOLUME_NAME, and set the disk name based on the
``disk-name`` property. This aligns with other disk drivers, and allows
for multiple instances of the sdmmc_subsys disk driver to be registered.

Add disk-name properties for all in tree definitions for the
sdmmc-subsys disk driver, and change all in tree usage of the disk name

Fixes #75004

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-11-05 15:25:10 -06:00
Riadh Ghaddab
46e1635773 fs: zms: multiple fixes from previous PR review
This resolves some addressed comments in this PR
https://github.com/zephyrproject-rtos/zephyr/pull/77930

It adds as well a section in the documentation about some
recommendations to increase ZMS performance.

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2024-10-29 07:07:13 -05:00
Phil Hindman
09574e68eb fs: littlefs: Gracefully fail when static buffers are too small
The cache_size and lookahead_size are set at compile time using the
CONFIG_FS_LITTLEFS_CACHE_SIZE and CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE values
from Kconfig, or from the cache-size and lookahead-size properties in a
'zephyr,fstab,littlefs' compatible in the devicetree.  Those values are
also used to statically allocate buffers that are pointed at by the
read_buffer, prog_buffer, and lookahead_buffer members of the lfs_config
structure.

At runtime, when using a block device, the cache_size and lookahead_size
are updated to be multiples of the underlying block device's block_size,
which may make them bigger than the original size used to allocate the
static buffers. Log an error and fail the operation when this occurs.

Signed-off-by: Phil Hindman <phindman@xes-inc.com>
2024-10-25 22:45:55 +01:00
Riadh Ghaddab
d4e246dfa1 fs: introduce ZMS a new Memory storage system
ZMS is the abreviation of Zephyr Memory Storage.
It is a storage developed to target especially the non erasable devices.

The new memory storage system inherit from the NVS storage multiple
features and introduce new ones :
* Inherited features :
 - light key-value based storage
 - cache for entries
 - Wear Leveling of flash memory
 - Resilience to power failures
* New features :
 - cycle counter for non erasable devices (instead of erase emulation)
 - Keys up to 32-bit
 - Built-in support of CRC32 for data
 - Small size data (<= 8 bytes) integrated within entries

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2024-10-24 16:57:12 +01:00
Phil Hindman
eea128aa8d fs: shell: Allow retries after a mount failure
Clean up if the mount command fails, such as due to a typo in the mount
point name, so that it can be retried.

Signed-off-by: Phil Hindman <phindman@xes-inc.com>
2024-10-21 18:38:37 -05:00
Jordan Yates
a1d6f8081a fs: fatfs: additional ELM FAT options
Make additional ELM FAT library options configurable to the user.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-11 13:20:08 -04:00
Jordan Yates
4235dbfd2b fs: fatfs: add missing dependency
Add a missing dependency on `!FS_FATFS_READ_ONLY`` for `FS_FATFS_MKFS`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-11 13:20:08 -04:00
Pisit Sawangvonganan
88374b0738 fs: nvs: streamline rc return logic
Streamline the `rc` return logic in `nvs_flash_wrt_entry()`, `nvs_gc()`
by directly returning `rc`, as the redundant conditional check and
explicit return of 0 were unnecessary.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-10-08 16:57:49 +02:00
Paul He
c2911af78e fs: littlefs: get block_cycles value from dts
Property "block-cycles" is required for node "zephyr,fstab,littlefs",
but source code did not get the value from dts file, now add it.

Additionally correct the wrong description of property "block-cycles"
in binding file.

Signed-off-by: Paul He <pawpawhe@gmail.com>
2024-10-07 18:43:05 +02:00
Adrien Ricciardi
cd76ab3428 fs: nvs: Simplified the initial loop in calc_free_space()
Replaced the initial loop that computes the initial free space
by a simple formula.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-10-03 11:41:33 +01:00
Jordan Yates
bf9584d6ba fs: add FILE_SYSTEM_LIB_LINK option
Add an option that links in the underlying file system libraries as
usual, but doesn't compile in the Zephyr file system abstraction layer.

This can be useful to avoid linking in the entire filesystem
implementation through the `fs_file_system_t` API struct if only a
subset of the functions are used.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-02 14:42:10 +01:00
Dominik Lau
319d67f7d3 fs: ext2: add alignment for superblock
Reading superblock didn't work with DMAs that only support aligned reads
(e.g. STM32 DMA).

Co-authored-by: Maciej Sobkowski <msobkowski@antmicro.com>
Signed-off-by: Dominik Lau <dlau@internships.antmicro.com>
2024-09-30 17:10:56 +01:00
Andrej Trnkóci
9ac8786bb2 fs: nvs: fix nvs static analysis error
There is asignment from size_t variable to uint8_t variable in
nvs_al_size function that can trigger static analysis error.
The problem is fixed by changing the variable to size_t type
instead of uint8_t.

Signed-off-by: Andrej Trnkóci <andrej.trnkoci@nxp.com>
2024-09-04 12:51:14 +02:00