@@ -527,9 +527,6 @@ static int settings_zms_save(struct settings_store *cs, const char *name, const
527
527
return rc ;
528
528
}
529
529
}
530
- #ifdef CONFIG_SETTINGS_ZMS_NO_LL_DELETE
531
- no_ll_update :
532
- #endif /* CONFIG_SETTINGS_ZMS_NO_LL_DELETE */
533
530
return 0 ;
534
531
}
535
532
@@ -548,16 +545,31 @@ static int settings_zms_get_last_hash_ids(struct settings_zms *cf)
548
545
rc = zms_read (& cf -> cf_zms , ll_last_hash_id , & settings_element ,
549
546
sizeof (settings_element ));
550
547
if (rc == - ENOENT ) {
551
- /* header doesn't exist or linked list broken, reinitialize the header */
552
- const struct settings_hash_linked_list settings_element = {
553
- .previous_hash = 0 , .next_hash = 0 };
554
- rc = zms_write (& cf -> cf_zms , ZMS_LL_HEAD_HASH_ID , & settings_element ,
555
- sizeof (struct settings_hash_linked_list ));
556
- if (rc < 0 ) {
557
- return rc ;
548
+ /* header doesn't exist or linked list broken, reinitialize the header
549
+ * if it doesn't exist and recover it if it is broken
550
+ */
551
+ if (ll_last_hash_id == ZMS_LL_HEAD_HASH_ID ) {
552
+ /* header doesn't exist */
553
+ const struct settings_hash_linked_list settings_element = {
554
+ .previous_hash = 0 , .next_hash = 0 };
555
+ rc = zms_write (& cf -> cf_zms , ZMS_LL_HEAD_HASH_ID , & settings_element ,
556
+ sizeof (struct settings_hash_linked_list ));
557
+ if (rc < 0 ) {
558
+ return rc ;
559
+ }
560
+ cf -> last_hash_id = ZMS_LL_HEAD_HASH_ID ;
561
+ cf -> second_to_last_hash_id = 0 ;
562
+ } else {
563
+ /* let's recover it by keeping all nodes until the last one */
564
+ const struct settings_hash_linked_list settings_element = {
565
+ .previous_hash = cf -> second_to_last_hash_id ,
566
+ .next_hash = 0 };
567
+ rc = zms_write (& cf -> cf_zms , cf -> last_hash_id , & settings_element ,
568
+ sizeof (struct settings_hash_linked_list ));
569
+ if (rc < 0 ) {
570
+ return rc ;
571
+ }
558
572
}
559
- cf -> last_hash_id = ZMS_LL_HEAD_HASH_ID ;
560
- cf -> second_to_last_hash_id = 0 ;
561
573
return 0 ;
562
574
} else if (rc < 0 ) {
563
575
return rc ;
0 commit comments