Commit graph

414 commits

Author SHA1 Message Date
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
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