Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
zms.h
Go to the documentation of this file.
1/* Copyright (c) 2018 Laczen
2 * Copyright (c) 2024 BayLibre SAS
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * ZMS: Zephyr Memory Storage
7 */
8#ifndef ZEPHYR_INCLUDE_FS_ZMS_H_
9#define ZEPHYR_INCLUDE_FS_ZMS_H_
10
11#include <sys/types.h>
13#include <zephyr/kernel.h>
14#include <zephyr/device.h>
15#include <zephyr/toolchain.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
35struct zms_fs {
55 bool ready;
59 const struct device *flash_device;
63 size_t ate_size;
64#if CONFIG_ZMS_LOOKUP_CACHE
66 uint64_t lookup_cache[CONFIG_ZMS_LOOKUP_CACHE_SIZE];
67#endif
68};
69
92int zms_mount(struct zms_fs *fs);
93
104int zms_clear(struct zms_fs *fs);
105
129ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len);
130
142int zms_delete(struct zms_fs *fs, uint32_t id);
143
160ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len);
161
180ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt);
181
196
211
221
238
243#ifdef __cplusplus
244}
245#endif
246
247#endif /* ZEPHYR_INCLUDE_FS_ZMS_H_ */
Public API for FLASH drivers.
ssize_t zms_calc_free_space(struct zms_fs *fs)
Calculate the available free space in the file system.
ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt)
Read a history entry from the file system.
ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len)
Write an entry to the file system.
int zms_sector_use_next(struct zms_fs *fs)
Close the currently active sector and switch to the next one.
int zms_mount(struct zms_fs *fs)
Mount a ZMS file system onto the device specified in fs.
ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len)
Read an entry from the file system.
size_t zms_active_sector_free_space(struct zms_fs *fs)
Tell how much contiguous free space remains in the currently active ZMS sector.
int zms_delete(struct zms_fs *fs, uint32_t id)
Delete an entry from the file system.
ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id)
Gets the length of the data that is stored in an entry with a given id
int zms_clear(struct zms_fs *fs)
Clear the ZMS file system from device.
Public kernel APIs.
__SIZE_TYPE__ ssize_t
Definition types.h:28
__INTPTR_TYPE__ off_t
Definition types.h:36
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
Flash memory parameters.
Definition flash.h:59
Mutex Structure.
Definition kernel.h:3026
Zephyr Memory Storage file system structure.
Definition zms.h:35
const struct flash_parameters * flash_parameters
Flash memory parameters structure.
Definition zms.h:61
uint64_t data_wra
Data write address.
Definition zms.h:45
const struct device * flash_device
Flash device runtime structure.
Definition zms.h:59
uint64_t ate_wra
Allocation Table Entry (ATE) write address.
Definition zms.h:43
size_t ate_size
Size of an Allocation Table Entry.
Definition zms.h:63
uint32_t sector_size
Storage system is split into sectors.
Definition zms.h:49
uint8_t sector_cycle
Current cycle counter of the active sector (pointed to by ate_wra)
Definition zms.h:53
uint32_t sector_count
Number of sectors in the file system.
Definition zms.h:51
off_t offset
File system offset in flash.
Definition zms.h:37
bool ready
Flag indicating if the file system is initialized.
Definition zms.h:55
struct k_mutex zms_lock
Mutex used to lock flash writes.
Definition zms.h:57
Macros to abstract toolchain specific capabilities.