Skip to content

Commit 8d7708a

Browse files
committed
[nrf fromtree] 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 <[email protected]> (cherry picked from commit 5f7cda5)
1 parent f8b341d commit 8d7708a

File tree

7 files changed

+242
-227
lines changed

7 files changed

+242
-227
lines changed

doc/services/storage/zms/zms.rst

Lines changed: 140 additions & 162 deletions
Large diffs are not rendered by default.

doc/zephyr.doxyfile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ INPUT = @ZEPHYR_BASE@/doc/_doxygen/mainpage.md \
980980
@ZEPHYR_BASE@/subsys/testsuite/include/ \
981981
@ZEPHYR_BASE@/subsys/testsuite/ztest/include/ \
982982
@ZEPHYR_BASE@/subsys/secure_storage/include/ \
983+
@ZEPHYR_BASE@/subsys/fs/zms/zms_priv.h \
983984

984985
# This tag can be used to specify the character encoding of the source files
985986
# that Doxygen parses. Internally Doxygen uses the UTF-8 encoding. Doxygen uses

include/zephyr/fs/zms.h

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,25 @@ struct zms_fs {
8080
* @brief Mount a ZMS file system onto the device specified in `fs`.
8181
*
8282
* @param fs Pointer to the file system.
83-
* @retval 0 Success
84-
* @retval -ERRNO Negative errno code on error
83+
*
84+
* @retval 0 on success.
85+
* @retval -ENOTSUP if the detected file system is not ZMS.
86+
* @retval -EPROTONOSUPPORT if the ZMS version is not supported.
87+
* @retval -EINVAL if any of the flash parameters or the sector layout is invalid.
88+
* @retval -ENXIO if there is a device error.
89+
* @retval -EIO if there is a memory read/write error.
8590
*/
8691
int zms_mount(struct zms_fs *fs);
8792

8893
/**
8994
* @brief Clear the ZMS file system from device.
9095
*
9196
* @param fs Pointer to the file system.
92-
* @retval 0 Success
93-
* @retval -ERRNO Negative errno code on error
97+
*
98+
* @retval 0 on success.
99+
* @retval -EACCES if `fs` is not mounted.
100+
* @retval -ENXIO if there is a device error.
101+
* @retval -EIO if there is a memory read/write error.
94102
*/
95103
int zms_clear(struct zms_fs *fs);
96104

@@ -102,65 +110,86 @@ int zms_clear(struct zms_fs *fs);
102110
* entry and an entry with data of length 0.
103111
*
104112
* @param fs Pointer to the file system.
105-
* @param id ID of the entry to be written
106-
* @param data Pointer to the data to be written
107-
* @param len Number of bytes to be written (maximum 64 KiB)
113+
* @param id ID of the entry to be written.
114+
* @param data Pointer to the data to be written.
115+
* @param len Number of bytes to be written (maximum 64 KiB).
108116
*
109117
* @return Number of bytes written. On success, it will be equal to the number of bytes requested
110118
* to be written or 0.
111119
* When a rewrite of the same data already stored is attempted, nothing is written to flash,
112120
* thus 0 is returned. On error, returns negative value of error codes defined in `errno.h`.
121+
* @retval Number of bytes written (`len` or 0) on success.
122+
* @retval -EACCES if ZMS is still not initialized.
123+
* @retval -ENXIO if there is a device error.
124+
* @retval -EIO if there is a memory read/write error.
125+
* @retval -EINVAL if `len` is invalid.
126+
* @retval -ENOSPC if no space is left on the device.
113127
*/
114128
ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len);
115129

116130
/**
117131
* @brief Delete an entry from the file system
118132
*
119133
* @param fs Pointer to the file system.
120-
* @param id ID of the entry to be deleted
121-
* @retval 0 Success
122-
* @retval -ERRNO Negative errno code on error
134+
* @param id ID of the entry to be deleted.
135+
*
136+
* @retval 0 on success.
137+
* @retval -EACCES if ZMS is still not initialized.
138+
* @retval -ENXIO if there is a device error.
139+
* @retval -EIO if there is a memory read/write error.
123140
*/
124141
int zms_delete(struct zms_fs *fs, uint32_t id);
125142

126143
/**
127144
* @brief Read an entry from the file system.
128145
*
129146
* @param fs Pointer to the file system.
130-
* @param id ID of the entry to be read
131-
* @param data Pointer to data buffer
132-
* @param len Number of bytes to read at most
147+
* @param id ID of the entry to be read.
148+
* @param data Pointer to data buffer.
149+
* @param len Number of bytes to read at most.
133150
*
134151
* @return Number of bytes read. On success, it will be equal to the number of bytes requested
135152
* to be read or less than that if the stored data has a smaller size than the requested one.
136153
* On error, returns negative value of error codes defined in `errno.h`.
154+
* @retval Number of bytes read (> 0) on success.
155+
* @retval -EACCES if ZMS is still not initialized.
156+
* @retval -EIO if there is a memory read/write error.
157+
* @retval -ENOENT if there is no entry with the given `id`.
137158
*/
138159
ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len);
139160

140161
/**
141162
* @brief Read a history entry from the file system.
142163
*
143164
* @param fs Pointer to the file system.
144-
* @param id ID of the entry to be read
145-
* @param data Pointer to data buffer
146-
* @param len Number of bytes to be read
165+
* @param id ID of the entry to be read.
166+
* @param data Pointer to data buffer.
167+
* @param len Number of bytes to be read.
147168
* @param cnt History counter: 0: latest entry, 1: one before latest ...
148169
*
149170
* @return Number of bytes read. On success, it will be equal to the number of bytes requested
150171
* to be read. When the return value is larger than the number of bytes requested to read this
151172
* indicates not all bytes were read, and more data is available. On error, returns negative
152173
* value of error codes defined in `errno.h`.
174+
* @retval Number of bytes read (> 0) on success.
175+
* @retval -EACCES if ZMS is still not initialized.
176+
* @retval -EIO if there is a memory read/write error.
177+
* @retval -ENOENT if there is no entry with the given `id` and history counter.
153178
*/
154179
ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt);
155180

156181
/**
157-
* @brief Gets the length of the data that is stored in an entry with a given ID
182+
* @brief Gets the length of the data that is stored in an entry with a given `id`
158183
*
159184
* @param fs Pointer to the file system.
160185
* @param id ID of the entry whose data length to retrieve.
161186
*
162187
* @return Data length contained in the ATE. On success, it will be equal to the number of bytes
163188
* in the ATE. On error, returns negative value of error codes defined in `errno.h`.
189+
* @retval Length of the entry with the given `id` (> 0) on success.
190+
* @retval -EACCES if ZMS is still not initialized.
191+
* @retval -EIO if there is a memory read/write error.
192+
* @retval -ENOENT if there is no entry with the given id and history counter.
164193
*/
165194
ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id);
166195

@@ -173,6 +202,9 @@ ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id);
173202
* still be written to the file system.
174203
* Calculating the free space is a time-consuming operation, especially on SPI flash.
175204
* On error, returns negative value of error codes defined in `errno.h`.
205+
* @retval Number of free bytes (>= 0) on success.
206+
* @retval -EACCES if ZMS is still not initialized.
207+
* @retval -EIO if there is a memory read/write error.
176208
*/
177209
ssize_t zms_calc_free_space(struct zms_fs *fs);
178210

@@ -181,7 +213,8 @@ ssize_t zms_calc_free_space(struct zms_fs *fs);
181213
*
182214
* @param fs Pointer to the file system.
183215
*
184-
* @return Number of free bytes.
216+
* @retval >=0 Number of free bytes in the currently active sector
217+
* @retval -EACCES if ZMS is still not initialized.
185218
*/
186219
size_t zms_active_sector_free_space(struct zms_fs *fs);
187220

@@ -196,7 +229,9 @@ size_t zms_active_sector_free_space(struct zms_fs *fs);
196229
*
197230
* @param fs Pointer to the file system.
198231
*
199-
* @return 0 on success. On error, returns negative value of error codes defined in `errno.h`.
232+
* @retval 0 on success.
233+
* @retval -EACCES if ZMS is still not initialized.
234+
* @retval -EIO if there is a memory read/write error.
200235
*/
201236
int zms_sector_use_next(struct zms_fs *fs);
202237

subsys/fs/zms/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#SPDX-License-Identifier: Apache-2.0
1+
# SPDX-License-Identifier: Apache-2.0
22

33
zephyr_sources(zms.c)

subsys/fs/zms/Kconfig

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
#Copyright (c) 2024 BayLibre SAS
1+
# Copyright (c) 2024 BayLibre SAS
22

3-
#SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: Apache-2.0
44

5-
#Zephyr Memory Storage ZMS
5+
# Zephyr Memory Storage ZMS
66

77
config ZMS
88
bool "Zephyr Memory Storage"
99
select CRC
1010
help
11-
Enable support of Zephyr Memory Storage.
11+
Enable Zephyr Memory Storage, which is a key-value storage system designed to work with
12+
all types of non-volatile storage technologies.
13+
It supports classical on-chip NOR flash as well as new technologies like RRAM and MRAM.
1214

1315
if ZMS
1416

@@ -20,28 +22,25 @@ config ZMS_LOOKUP_CACHE
2022
table entry (ATE) for all ZMS IDs that fall into that cache position.
2123

2224
config ZMS_LOOKUP_CACHE_SIZE
23-
int "ZMS Storage lookup cache size"
25+
int "ZMS lookup cache size"
2426
default 128
2527
range 1 65536
2628
depends on ZMS_LOOKUP_CACHE
2729
help
28-
Number of entries in ZMS lookup cache.
29-
It is recommended that it should be a power of 2.
30-
Every additional entry in cache will add 8 bytes in RAM
30+
Number of entries in the ZMS lookup cache.
31+
Every additional entry in cache will use 8 bytes of RAM.
3132

3233
config ZMS_DATA_CRC
33-
bool "ZMS DATA CRC"
34-
help
35-
Enables DATA CRC
34+
bool "ZMS data CRC"
3635

3736
config ZMS_CUSTOMIZE_BLOCK_SIZE
3837
bool "Customize the size of the buffer used internally for reads and writes"
3938
help
4039
ZMS uses an internal buffer to read/write and compare stored data.
4140
Increasing the size of this buffer should be done carefully in order to not
4241
overflow the stack.
43-
Increasing this buffer means as well that ZMS could work with storage devices
44-
that have larger write-block-size which decreases ZMS performance
42+
Increasing it makes ZMS able to work with storage devices
43+
that have a larger `write-block-size` (which decreases the performance of ZMS).
4544

4645
config ZMS_CUSTOM_BLOCK_SIZE
4746
int "ZMS internal buffer size"

subsys/fs/zms/zms.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ static int zms_init(struct zms_fs *fs)
11011101
/* Let's check that we support this ZMS version */
11021102
if (ZMS_GET_VERSION(empty_ate.metadata) != ZMS_DEFAULT_VERSION) {
11031103
LOG_ERR("ZMS Version is not supported");
1104-
rc = -ENOEXEC;
1104+
rc = -EPROTONOSUPPORT;
11051105
goto end;
11061106
}
11071107
}
@@ -1125,7 +1125,7 @@ static int zms_init(struct zms_fs *fs)
11251125
}
11261126
/* all sectors are closed, and zms magic number not found. This is not a zms fs */
11271127
if ((closed_sectors == fs->sector_count) && !zms_magic_exist) {
1128-
rc = -EDEADLK;
1128+
rc = -ENOTSUP;
11291129
goto end;
11301130
}
11311131
/* TODO: add a recovery mechanism here if the ZMS magic number exist but all
@@ -1157,7 +1157,7 @@ static int zms_init(struct zms_fs *fs)
11571157
/* Let's check the version */
11581158
if (ZMS_GET_VERSION(empty_ate.metadata) != ZMS_DEFAULT_VERSION) {
11591159
LOG_ERR("ZMS Version is not supported");
1160-
rc = -ENOEXEC;
1160+
rc = -EPROTONOSUPPORT;
11611161
goto end;
11621162
}
11631163
}

subsys/fs/zms/zms_priv.h

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
#ifndef __ZMS_PRIV_H_
99
#define __ZMS_PRIV_H_
1010

11-
#ifdef __cplusplus
12-
extern "C" {
13-
#endif
14-
1511
/*
16-
* MASKS AND SHIFT FOR ADDRESSES
17-
* an address in zms is an uint64_t where:
18-
* high 4 bytes represent the sector number
19-
* low 4 bytes represent the offset in a sector
12+
* MASKS AND SHIFT FOR ADDRESSES.
13+
* An address in zms is an uint64_t where:
14+
* - high 4 bytes represent the sector number
15+
* - low 4 bytes represent the offset in a sector
2016
*/
2117
#define ADDR_SECT_MASK GENMASK64(63, 32)
2218
#define ADDR_SECT_SHIFT 32
@@ -44,34 +40,40 @@ extern "C" {
4440
#define ZMS_INVALID_SECTOR_NUM -1
4541
#define ZMS_DATA_IN_ATE_SIZE 8
4642

43+
/**
44+
* @ingroup zms_data_structures
45+
* ZMS Allocation Table Entry (ATE) structure
46+
*/
4747
struct zms_ate {
48-
uint8_t crc8; /* crc8 check of the entry */
49-
uint8_t cycle_cnt; /* cycle counter for non erasable devices */
50-
uint16_t len; /* data len within sector */
51-
uint32_t id; /* data id */
48+
/** crc8 check of the entry */
49+
uint8_t crc8;
50+
/** cycle counter for non erasable devices */
51+
uint8_t cycle_cnt;
52+
/** data len within sector */
53+
uint16_t len;
54+
/** data id */
55+
uint32_t id;
5256
union {
53-
uint8_t data[8]; /* used to store small size data */
57+
/** data field used to store small sized data */
58+
uint8_t data[8];
5459
struct {
55-
uint32_t offset; /* data offset within sector */
60+
/** data offset within sector */
61+
uint32_t offset;
5662
union {
57-
uint32_t data_crc; /*
58-
* crc for data: The data CRC is checked only
59-
* when the whole data of the element is read.
60-
* The data CRC is not checked for a partial
61-
* read, as it is computed for the complete
62-
* set of data.
63-
*/
64-
uint32_t metadata; /*
65-
* Used to store metadata information
66-
* such as storage version.
67-
*/
63+
/**
64+
* crc for data: The data CRC is checked only when the whole data
65+
* of the element is read.
66+
* The data CRC is not checked for a partial read, as it is computed
67+
* for the complete set of data.
68+
*/
69+
uint32_t data_crc;
70+
/**
71+
* Used to store metadata information such as storage version.
72+
*/
73+
uint32_t metadata;
6874
};
6975
};
7076
};
7177
} __packed;
7278

73-
#ifdef __cplusplus
74-
}
75-
#endif
76-
7779
#endif /* __ZMS_PRIV_H_ */

0 commit comments

Comments
 (0)