@@ -61,6 +61,7 @@ static int settings_zms_dst(struct settings_zms *cf)
6161 return 0 ;
6262}
6363
64+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
6465static int settings_zms_unlink_ll_node (struct settings_zms * cf , uint32_t name_hash )
6566{
6667 int rc = 0 ;
@@ -119,6 +120,7 @@ static int settings_zms_unlink_ll_node(struct settings_zms *cf, uint32_t name_ha
119120
120121 return rc ;
121122}
123+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
122124
123125static int settings_zms_delete (struct settings_zms * cf , uint32_t name_hash )
124126{
@@ -131,7 +133,7 @@ static int settings_zms_delete(struct settings_zms *cf, uint32_t name_hash)
131133 if (rc < 0 ) {
132134 return rc ;
133135 }
134-
136+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
135137 rc = settings_zms_unlink_ll_node (cf , name_hash );
136138 if (rc < 0 ) {
137139 return rc ;
@@ -142,7 +144,14 @@ static int settings_zms_delete(struct settings_zms *cf, uint32_t name_hash)
142144 if (rc < 0 ) {
143145 return rc ;
144146 }
147+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
145148
149+ #if defined(CONFIG_SETTINGS_ZMS_NAME_CACHE ) && defined (CONFIG_SETTINGS_ZMS_NO_LL_DELETE )
150+ /* This will invalidate the name_hash in cache and will force reading it again when
151+ * writing the same name.
152+ */
153+ settings_zms_cache_add (cf , name_hash & ZMS_HASH_MASK , 1 );
154+ #endif
146155 return rc ;
147156}
148157
@@ -211,15 +220,26 @@ static int settings_zms_load(struct settings_store *cs, const struct settings_lo
211220 ZMS_NAME_HASH_ID (ll_hash_id ) + ZMS_DATA_ID_OFFSET );
212221
213222 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.
223+ /* In case we are not updating the linked list, this is an empty mode
224+ * Just continue
225+ */
226+ #ifndef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
227+ /* Otherwise, Settings item is not stored correctly in the ZMS.
228+ * ZMS entry for its name or value is either missing or deleted.
229+ * Clean dirty entries to make space for future settings item.
218230 */
219231 ret = settings_zms_delete (cf , ZMS_NAME_HASH_ID (ll_hash_id ));
220232 if (ret < 0 ) {
221233 return ret ;
222234 }
235+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
236+ /* update next ll_hash_id */
237+ ret = zms_read (& cf -> cf_zms , ll_hash_id , & settings_element ,
238+ sizeof (struct settings_hash_linked_list ));
239+ if (ret < 0 ) {
240+ return ret ;
241+ }
242+ ll_hash_id = settings_element .next_hash ;
223243 continue ;
224244 }
225245
@@ -287,7 +307,7 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
287307 }
288308#endif
289309
290- /* Let's find out if there is no hash collisions in the storage */
310+ /* Let's find out if there are hash collisions in the storage */
291311 write_name = true;
292312 hash_collision = true;
293313
@@ -363,6 +383,17 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
363383 if (rc < 0 ) {
364384 return rc ;
365385 }
386+ #ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
387+ /* verify that the ll_node doesn't exist otherwise do not update it */
388+ rc = zms_read (& cf -> cf_zms , name_hash | 1 , & settings_element ,
389+ sizeof (struct settings_hash_linked_list ));
390+ if (rc >= 0 ) {
391+ goto no_ll_update ;
392+ } else if (rc != - ENOENT ) {
393+ return rc ;
394+ }
395+ /* else the LL node doesn't exist let's update it */
396+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
366397 /* write linked list structure element */
367398 settings_element .next_hash = 0 ;
368399 /* Verify first that the linked list last element is not broken.
@@ -392,7 +423,9 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
392423 cf -> second_to_last_hash_id = cf -> last_hash_id ;
393424 cf -> last_hash_id = name_hash | 1 ;
394425 }
395-
426+ #ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
427+ no_ll_update :
428+ #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
396429#if CONFIG_SETTINGS_ZMS_NAME_CACHE
397430 if (!name_in_cache ) {
398431 settings_zms_cache_add (cf , name_hash & ZMS_HASH_MASK ,
0 commit comments