Commit graph

427 commits

Author SHA1 Message Date
Anas Nashif
303af992e5 style: fix 'if (' usage in cmake files
Replace with 'if(' and 'else(' per the cmake style guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-29 11:44:13 +02:00
Riadh Ghaddab
a5f0c965c5 zms: fix init if a faulty bit is detected in the next free location
For devices that need an erase before a write, ZMS do not verify that
the next available location in the open sector is filled with the
erase_value.
Fix this by adding a check at init.

Signed-off-by: Riadh Ghaddab <rghaddab@baylibre.com>
2025-10-17 21:02:20 -04:00
Maciej Zagrabski
b69b064242 fs: littlefs: add api call for lfs_fs_gc
Lfs provide lfs_fs_gc function for some time now.
Function allow offloading of expensive block allocation scan.

Introduce lfs_fs_gc via api call fc_gc.

Signed-off-by: Maciej Zagrabski <mzi@trackunit.com>
2025-10-10 13:00:05 -04:00
Dominik Ermel
f5e70d56be fs: ext2: Explicit int cast ret assignment in ext2_init_storage
Adds cast to int when ret is assigned error code returned by
functions that return int64_t. The cast has been added to indicate
that assignment with truncation is here intentional.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2025-10-08 08:42:18 +02:00
Jakub Michalski
a0dbd67262 fs: virtiofs: fix off-by-one in virtqueue initialization
REQUEST_QUEUE was passed as queue_num to virtio_init_virtqueues
where REQUEST_QUEUE+1 was required

Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2025-10-02 21:59:01 +02:00
Grzegorz Swiderski
335e1c2a97 Revert "fs: zms: Add FLASH_MAP dependency"
This reverts commit 77f19eb1b5.

This dependency was misplaced. See the parent commit.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-09-30 15:29:59 +03:00
Grzegorz Swiderski
620bf58a1e zms: Initial support for 64 bit IDs
Allow the ZMS API to optionally accept 64 bit IDs. A typedef `zms_id_t`
is added, so that the maximum ID width can be controlled using Kconfig.

The current ATE structure is already large enough that it is possible to
reserve 64 bits for IDs without increasing its total size (128 bits).
This makes the feature a natural, low footprint alternative to Settings,
for cases where the supported key namespace must be larger than 32 bit
but not arbitrarily large.

The ATE format does have to be altered to accommodate larger IDs, but
the default "32 bit" format is left as is. Now, the `struct zms_ate`
describes one of two supported formats, selected by an `#if` condition.
In the future, it may be possible to support multiple ATE formats at
runtime, in which case the structure can be turned into a union.

In the new, "64 bit" ATEs, the `offset` and `metadata` fields are moved
into a union, because they are found to be mutually exclusive. With the
old format, the same fields are in different locations, but one of them
always gets filled with a dummy value, depending on the given ATE type.
To cover both cases, a `memset` is used, which should be optimized away
by the compiler when appropriate.

The only limitation is that the new ATE format has no room for data CRC,
but an alternative integrity check can be implemented by the caller.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-09-25 14:17:24 -04:00
James Roy
889a713ca2 subsystem: fs: Use better wrapper macros
Replace `DT_INST_PROP(inst, mount_point)` with
`FSTAB_ENTRY_DT_INST_MOUNT_POINT(inst)`.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-09-24 15:49:36 +01:00
Alberto Escolar Piedras
b86e52bd6f subsys/fs/fuse: Support using libfuse3
Support using FUSE v3, instead of FUSE v2.

FUSE v3 has been out for a couple of years now, so most distributions
have it.
But note the FUSE library (and its v3 branch) is currently unmaintained,
and older distributions do not ship it.

Some Linux distros have transitioned their packages away from fuse2.
Which results in less atention in these distros to fuse2, and therefore
a higher likelyhood that there would be distribution issues with the
corresponding packages.
There is also some likelihood the fuse2 packages may be eventually
droped by some of these.

So let's support either version, with a kconfig adapting to either API
and their quirks.

Note that both the fuse2 and fuse3 library code have quite a few
sideeffects on the process that uses it.

By now we continue defaulting to fuse2 as it is the most common.
But users can select to use the v3 if they have an issue w v2 or want
to start trying out using v3.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-09-22 13:30:46 -04:00
Alberto Escolar Piedras
24252e2ac4 subsys/fs/fuse: Avoid possible race
Avoid a possible race between the FUSE thread and the Zephyr threads
during init.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-09-22 13:30:46 -04:00
Alberto Escolar Piedras
129e50cd34 subsys/fs/fuse: Misc build fixes
FUSE_INCLUDE_DIRS should be passed to the native_simulator build.
If there is several fuse libraries installed, we need to ensure the
bottom side of the driver is built with the correct include paths.
(These includes are irrelevant for the Zephyr side build)

Support having a list of include paths instead of single one.

Support having a list of libraries to link to instead of a single one.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-09-22 13:30:46 -04:00
Jordan Yates
aa9123606c fs: zms: fix delete non-existent with cache
Fix deleting a key that doesn't exist from writing a new entry to the
filesystem when `CONFIG_ZMS_NO_DOUBLE_WRITE` and
`CONFIG_ZMS_LOOKUP_CACHE` are enabled.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-09-22 13:28:28 -04:00
Jordan Yates
ff020ec8a0 fs: zms: fix no-cache + no-double-write
Fix a compiler error when `CONFIG_ZMS_NO_DOUBLE_WRITE=y` and
`CONFIG_ZMS_LOOKUP_CACHE=n`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-09-22 13:28:28 -04:00
Utsav Munendra
2a6d692937 fs: Shell command ls to list file sizes
List the file size helps in developer debugging experience. Provide
a config to disable new behavior in case any users depended on
command output to be a list.

Signed-off-by: Utsav Munendra <utsavm@meta.com>
2025-09-10 13:02:31 +02:00
Benjamin Cabé
0132ea07fb doc: fix spelling errors tree-wide
fix some spelling errors in code comments and Kconfig helps

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-03 17:04:13 +02:00
Theis Mejnertsen
aca602f2d0 fs: zms: add input validation of fs pointer for api
Add checks on the fs pointer passed through the api before using to
avoid causing an exception

Signed-off-by: Theis Mejnertsen <theismejnertsen@gmail.com>
2025-09-02 15:54:17 +02:00
Theis Mejnertsen
4e4482205f fs: zms: make zms_active_sector_free_space return type signed
zms_active_sector_free_space is documented to return -EACCES on fs not
mounted error but currently returns an usigned type size_t. This fixes
that by changing the return value into a ssize_t

Signed-off-by: Theis Mejnertsen <theismejnertsen@gmail.com>
2025-09-02 15:54:17 +02:00
Mike J. Chen
ebab75bb73 nvs: support sector_size of 64KB
Allows NVS to work with flash device configured to
use only 64KB block erase. Due to how addresses
are encoded internally in NVS, 64KB is the maximum
sector size. Add a test for this during mount.

Add a native_sim unit test case for 64kb erase block size

Signed-off-by: Mike J. Chen <mjchen@google.com>
2025-08-26 16:13:23 +02:00
Bas van Loon
1dcf123e2d fs/ext2: Fix NULL dereference when fs_stat queries root.
When fs_stat() queries the root / mountpoint it should return its root
i_node but instead it tries to return the parent i_node which does not
exist. Fix this by checking if parent is set otherwise return the root
i_node.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/94000.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2025-08-06 21:34:29 -04:00
Bas van Loon
88a09e6379 fs: Implement fstab devicetree integration for EXT2
Device tree and/or automount support was not present and might be useful
when for example the settings module needs early access to a filesystem.
This patch adds support to mount an EXT2 filesystem automatically. The
implementation chosen is to provide the drive name matching a disk
drive specified in the device tree ie on an (e)MMC or SD card.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2025-08-02 13:18:15 +02:00
Jamie McCrae
77f19eb1b5 fs: zms: Add FLASH_MAP dependency
ZMS does not work without this and gives compilation errors, fix
this by adding the correct dependency

Signed-off-by: Jamie McCrae <spam@helper3000.net>
2025-08-01 19:38:48 +01:00
Joakim Andersson
0fde156b9c fs: shell: Fix FS shell using fixed storage_partition name instead of DT
Fix FS shell using fixed 'storage_partition' nodelabel instead of
accessing the DT defined partition from the zephyr,fstab,littlefs
node partition property.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2025-07-24 02:48:22 -04:00
Jakub Michalski
77834f2069 fs: implement zephyr fs api for virtiofs
This commit implements zephyr filesystem operations for virtiofs

Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2025-07-23 12:20:22 -04:00
Jakub Michalski
02b18136e2 fs: add virtiofs operations
This commit adds virtiofs functions implementing fuse operations required
to enable zephyr filesystem support

Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2025-07-23 12:20:22 -04:00
Jakub Michalski
b28483a3fe fs: add fuse primitives
This commit adds fuse structures, requests and functions to fill them

Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2025-07-23 12:20:22 -04:00
Alberto Escolar Piedras
8270444a4d subsys/fs/fuse_fs_access: Remove NATIVE_APPLICATION support
It is not possible to build anymore in that mode, so we do not
need to support it in this driver cmake files.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-19 09:38:15 +02:00
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