@@ -31,6 +31,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
3131 size_t val_len );
3232static void * settings_zms_storage_get (struct settings_store * cs );
3333static int settings_zms_get_last_hash_ids (struct settings_zms * cf );
34+ static void settings_zms_cache_add (struct settings_zms * cf , uint32_t name_hash , bool has_collision );
3435
3536static struct settings_store_itf settings_zms_itf = {.csi_load = settings_zms_load ,
3637 .csi_save = settings_zms_save ,
@@ -61,6 +62,7 @@ static int settings_zms_dst(struct settings_zms *cf)
6162 return 0 ;
6263}
6364
65+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
6466static int settings_zms_unlink_ll_node (struct settings_zms * cf , uint32_t name_hash )
6567{
6668 int rc = 0 ;
@@ -119,6 +121,7 @@ static int settings_zms_unlink_ll_node(struct settings_zms *cf, uint32_t name_ha
119121
120122 return rc ;
121123}
124+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
122125
123126static int settings_zms_delete (struct settings_zms * cf , uint32_t name_hash )
124127{
@@ -131,7 +134,7 @@ static int settings_zms_delete(struct settings_zms *cf, uint32_t name_hash)
131134 if (rc < 0 ) {
132135 return rc ;
133136 }
134-
137+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
135138 rc = settings_zms_unlink_ll_node (cf , name_hash );
136139 if (rc < 0 ) {
137140 return rc ;
@@ -142,7 +145,14 @@ static int settings_zms_delete(struct settings_zms *cf, uint32_t name_hash)
142145 if (rc < 0 ) {
143146 return rc ;
144147 }
148+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
145149
150+ #if defined(CONFIG_SETTINGS_ZMS_NAME_CACHE ) && defined (CONFIG_SETTINGS_ZMS_NO_LL_DELETE )
151+ /* This will invalidate the name_hash in cache and will force reading it again when
152+ * writing the same name.
153+ */
154+ settings_zms_cache_add (cf , name_hash & ZMS_HASH_MASK , 1 );
155+ #endif
146156 return rc ;
147157}
148158
@@ -211,15 +221,26 @@ static int settings_zms_load(struct settings_store *cs, const struct settings_lo
211221 ZMS_NAME_HASH_ID (ll_hash_id ) + ZMS_DATA_ID_OFFSET );
212222
213223 if ((rc1 <= 0 ) || (rc2 <= 0 )) {
214- /* Settings item is not stored correctly in the ZMS.
215- * ZMS entry for its name or value is either missing
216- * or deleted. Clean dirty entries to make space for
217- * future settings item.
224+ /* In case we are not updating the linked list, this is an empty mode
225+ * Just continue
226+ */
227+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
228+ /* Otherwise, Settings item is not stored correctly in the ZMS.
229+ * ZMS entry for its name or value is either missing or deleted.
230+ * Clean dirty entries to make space for future settings item.
218231 */
219232 ret = settings_zms_delete (cf , ZMS_NAME_HASH_ID (ll_hash_id ));
220233 if (ret < 0 ) {
221234 return ret ;
222235 }
236+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
237+ /* update next ll_hash_id */
238+ ret = zms_read (& cf -> cf_zms , ll_hash_id , & settings_element ,
239+ sizeof (struct settings_hash_linked_list ));
240+ if (ret < 0 ) {
241+ return ret ;
242+ }
243+ ll_hash_id = settings_element .next_hash ;
223244 continue ;
224245 }
225246
@@ -287,7 +308,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
287308 }
288309#endif
289310
290- /* Let's find out if there is no hash collisions in the storage */
311+ /* Let's find out if there are hash collisions in the storage */
291312 write_name = true;
292313 hash_collision = true;
293314
@@ -363,6 +384,17 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
363384 if (rc < 0 ) {
364385 return rc ;
365386 }
387+ #ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
388+ /* verify that the ll_node doesn't exist otherwise do not update it */
389+ rc = zms_read (& cf -> cf_zms , name_hash | 1 , & settings_element ,
390+ sizeof (struct settings_hash_linked_list ));
391+ if (rc >= 0 ) {
392+ goto no_ll_update ;
393+ } else if (rc != - ENOENT ) {
394+ return rc ;
395+ }
396+ /* else the LL node doesn't exist let's update it */
397+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
366398 /* write linked list structure element */
367399 settings_element .next_hash = 0 ;
368400 /* Verify first that the linked list last element is not broken.
@@ -392,7 +424,9 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
392424 cf -> second_to_last_hash_id = cf -> last_hash_id ;
393425 cf -> last_hash_id = name_hash | 1 ;
394426 }
395-
427+ #ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
428+ no_ll_update :
429+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
396430#if CONFIG_SETTINGS_ZMS_NAME_CACHE
397431 if (!name_in_cache ) {
398432 settings_zms_cache_add (cf , name_hash & ZMS_HASH_MASK ,
0 commit comments