This commit fixes removing indirect blocks (marking them as 0)
in the inode structure. Previous version of the code was removing
the top-level blocks only when the first removed block was
one of the first 12 direct blocks. However, when the first removed
block is the first block in the referenced block list, its parent
(indirect block) should also be removed.
Signed-off-by: Franciszek Pindel <fpindel@antmicro.com>
First sector starts at CONFIG_EXT2_DISK_STARTING_SECTOR.
This commit fixes calculating free space, based on that value.
Signed-off-by: Franciszek Pindel <fpindel@antmicro.com>
The commit adds dependency on Kconfig FLASH_PAGE_LAYOUT to subsystems
that really require it:
FCB, NVS, LittleFS
and removes direct selection from '*.conf' files where no longer
needed.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Users should be able to call fs_mkfs() manually even if FS_FATFS_MOUNT_MKFS
is disabled.
Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
Replace the use of a memcmp of a temp buffer filled with
the comparison value with a direct comparison of
the read buffer contents.
Improves speed of the function (no more memset() call)
and reduces stack usage.
Signed-off-by: Mike J. Chen <mjchen@google.com>
Add warning that file opened without R/W flags will have no read/write
access.
Remove suggestion for using fs_open to check if file exists.
Clarify -ENOENT return reason.
Fixes#64030
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Non-configurable init priority POST_KERNEL/99 might
be too late for certain uses cases (e.g. fetching data from
the file system in driver initialization). Chabge it to
be configurable so that applications can mount the
file systems earlies if they want.
Signed-off-by: Miika Karanki <miika.karanki@vaisala.com>
fs_init was just initializing mutex and dlist. Those can be
done statically. Not having the SYS_INIT function helps
in ordering the init functions in case e.g. file system
mounts are wanted to happen early stage on the system
startup.
Signed-off-by: Miika Karanki <miika.karanki@vaisala.com>
For native_sim we need to have the fuse library linked with the
native simulator runner, not with the embedded code.
Let's fix it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.
Rename it to random.h and get consistently with other
subsystems.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
NVS lookup cache currently uses CRC8/16 as a hash function
to determine the cache position, which is not ideal choice.
For example, when NVS lookup cache size is 512 and 256
subsequent NVS IDs are written (that is, 0, 1.., 255), this
results in 128 cache collisions.
It is better to use a dedicated integer hash function. This
PR uses one of the 16-bit integer hash functions discovered
with https://github.com/skeeto/hash-prospector project. The
hash function was additionally tested in the context of NVS
lookup cache using simple NVS ID allocation patterns as well
as using real device NVS dump.
Also, add a test case to verify that the hash function is
not extremely bad.
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
Modify the signature of the k_mem_slab_free() function with a new one,
replacing the old void **mem with void *mem as a parameter.
The following function:
void k_mem_slab_free(struct k_mem_slab *slab, void **mem);
has the wrong signature. mem is only used as a regular pointer, so there
is no need to use a double-pointer. The correct signature should be:
void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
The issue with the current signature, although functional, is that it is
extremely confusing. I myself, a veteran Zephyr developer, was confused
by this parameter when looking at it recently.
All in-tree uses of the function have been adapted.
Fixes#61888.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
For flash device, littlefs should be located at the partition.
Current implementation of the fs shell is hardcoded for the flash device
and the compilation fails if STORAGE_PARTITION isn't defined in the
device tree.
Add options for block dev support. This allows to mount littlefs on the
block device from the shell, and also removes the compile time
dependency on STORAGE_PARTITION, if CONFIG_FS_LITTLEFS_BLK_DEV is set.
Fix mounting of littlefs blk device. lfs_mount stucks in case when the
read/prog buffer less than SDMMC block size, because it can cause memory
corrupt, for example, look into function 'card_read_blocks' how it writes
data to read buffer in case when buffer isn't aligned. With default
config we have 32 bytes in the read buffer but trying to write
'block_size' to it and get memory corrupt, the same issue will be in
case when the read buffer is aligned.
This is an incremental improvement, ideally, someone should implement
selection of the storage dev from the shell args.
Co-authored-by: Mykola Kvach <mykola_kvach@epam.com>
Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
dev_id is used as a pointer at the end of the call chain, so passing it
as an int makes no sense and can cause crashes if the pointer and int
types have different sizes. For example, if we have 64-bit pointers on
a board, the higher part of dev_id will be removed due to an type cast.
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
This commits changes how data on the disk is accessed. There are disk
structures which are packed and their fields are stored in little endian
byte order. To use data in the program structures it has to be translated
from little endian to cpu endianness.
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
- `ext2_file` and `ext2_dir` merged into one struct and allocated from
dedicated slab
- `ext2_inode` allocated from dedicated slab
- `ext2_disk_dentry` allocated from heap (because their size is not
constant)
- `ext2_bgroup` and `ext2_disk_superblock` statically allocated
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Fix the behavior when data should be written to storage device. Now all
writes are done directly to disk_access layer (where it might possibly
be cached).
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Added funtion that takes specified action when file system corruption is
detected. Possible actions are: do nothing, make mount point read-only,
panic.
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Changes:
- Added few assertions to check if some assumptions are correct
- Fix removing blocks during trucate and inode removal
- Clear entry in inode table after inode has been removed
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Changes:
- Add fs::sync function
- Make correct file system in mkfs
- Add few assertions to ensure that all assumptions are correct
Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
nvs_sector_close has not been initializing nvs_ate.part, before
writing it to flash.
Fixes#58699
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
LittleFS may be used not only for Flash devices, we can use it for
block devices too.
Add possibility of building LittleFS for case when
CONFIG_FLASH_MAP and CONFIG_FLASH_PAGE_LAYOUT are disabled.
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
LittleFS may be used not only for Flash devices, we can use it for block
devices too. So, I have changed dependency rules and remove dependency
on flash map from FILE_SYSTEM_LITTLEFS.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
Signed-off-by: Mykola Kvach <mykola_kvach@epam.com>
Mounting the disk in a global function can lead to an issue
where fatFS cannot be mounted due to it not being registered beforehand.
To solve this problem, fatFS is now initialized in POST_KERNEL,
just like the littleFS initialization function.
fatfs_init must be called before attempting to mounte the disk.
Signed-off-by: Sihyun Noh <awake_noh@naver.com>
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
When lfs mount fails and there is no formatting requested, the return
code must be translated to errno before being passed to the application
layer.
Additionally, only log a warning that the FS will be formatted, when the
system is not read-only.
Fixes#56378
Signed-off-by: Manuel Arguelles <manuel.arguelles@nxp.com>
The commit changes the fs_mount to not allow mounting same system,
with the same private data pointer, at two different mount paths.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit enables zephyr to configure the FatFs FF_FS_REENTRANT
option and support fs actions from multiple threads.
CONFIG_FS_FATFS_REENTRANT enables the option and provides zephyr
mutex wrappers.
Signed-off-by: Nicola Ochsenbein <Nicola.Ochsenbein@husqvarnagroup.com>
NVS cache was used only in read function. This commit add the usage of
NVS cache in write and gc functions.
Signed-off-by: Julien D'Ascenzio <julien.dascenzio@paratronic.fr>