@@ -29,8 +29,10 @@ static int zms_ate_valid_different_sector(struct zms_fs *fs, const struct zms_at
2929
3030#ifdef CONFIG_ZMS_LOOKUP_CACHE
3131
32- static inline size_t zms_lookup_cache_pos (zms_id_t id )
32+ static inline size_t zms_lookup_cache_pos (uint32_t id )
3333{
34+ uint32_t hash = id ;
35+
3436#ifdef CONFIG_ZMS_LOOKUP_CACHE_FOR_SETTINGS
3537 /*
3638 * 1. Settings subsystem is storing the name ID and the linked list node ID
@@ -50,26 +52,14 @@ static inline size_t zms_lookup_cache_pos(zms_id_t id)
5052 uint32_t key_value_bit ;
5153 uint32_t key_value_hash ;
5254 uint32_t key_value_ll ;
53- uint32_t hash ;
5455
5556 key_value_bit = (id >> LOG2 (ZMS_DATA_ID_OFFSET )) & 1 ;
5657 key_value_hash = (id & ZMS_HASH_MASK ) >> (CONFIG_SETTINGS_ZMS_MAX_COLLISIONS_BITS + 1 );
5758 key_value_ll = id & BIT (0 );
5859
5960 hash = (key_value_hash << 2 ) | (key_value_bit << 1 ) | key_value_ll ;
60- #elif defined(CONFIG_ZMS_ID_64BIT )
61- /* 64-bit integer hash function found by https://github.com/skeeto/hash-prospector. */
62- uint64_t hash = id ;
63-
64- hash ^= hash >> 32 ;
65- hash *= 0x42ab4abe4c475039ULL ;
66- hash ^= hash >> 31 ;
67- hash *= 0xfa90c4424c537791ULL ;
68- hash ^= hash >> 32 ;
6961#else
7062 /* 32-bit integer hash function found by https://github.com/skeeto/hash-prospector. */
71- uint32_t hash = id ;
72-
7363 hash ^= hash >> 16 ;
7464 hash *= 0x7feb352dU ;
7565 hash ^= hash >> 15 ;
@@ -249,7 +239,7 @@ static int zms_flash_ate_wrt(struct zms_fs *fs, const struct zms_ate *entry)
249239 goto end ;
250240 }
251241#ifdef CONFIG_ZMS_LOOKUP_CACHE
252- /* ZMS_HEAD_ID is a special-purpose identifier. Exclude it from the cache */
242+ /* 0xFFFFFFFF is a special-purpose identifier. Exclude it from the cache */
253243 if (entry -> id != ZMS_HEAD_ID ) {
254244 fs -> lookup_cache [zms_lookup_cache_pos (entry -> id )] = fs -> ate_wra ;
255245 }
@@ -497,7 +487,7 @@ static bool zms_close_ate_valid(struct zms_fs *fs, const struct zms_ate *entry)
497487/* zms_empty_ate_valid validates an sector empty ate.
498488 * A valid sector empty ate should be:
499489 * - a valid ate
500- * - with len = 0xffff and id = ZMS_HEAD_ID
490+ * - with len = 0xffff and id = 0xffffffff
501491 * return true if valid, false otherwise
502492 */
503493static bool zms_empty_ate_valid (struct zms_fs * fs , const struct zms_ate * entry )
@@ -510,7 +500,7 @@ static bool zms_empty_ate_valid(struct zms_fs *fs, const struct zms_ate *entry)
510500 * Valid gc_done_ate:
511501 * - valid ate
512502 * - len = 0
513- * - id = ZMS_HEAD_ID
503+ * - id = 0xffffffff
514504 * return true if valid, false otherwise
515505 */
516506static bool zms_gc_done_ate_valid (struct zms_fs * fs , const struct zms_ate * entry )
@@ -546,7 +536,7 @@ static int zms_validate_closed_sector(struct zms_fs *fs, uint64_t addr, struct z
546536}
547537
548538/* store an entry in flash */
549- static int zms_flash_write_entry (struct zms_fs * fs , zms_id_t id , const void * data , size_t len )
539+ static int zms_flash_write_entry (struct zms_fs * fs , uint32_t id , const void * data , size_t len )
550540{
551541 int rc ;
552542 struct zms_ate entry ;
@@ -559,13 +549,13 @@ static int zms_flash_write_entry(struct zms_fs *fs, zms_id_t id, const void *dat
559549 entry .cycle_cnt = fs -> sector_cycle ;
560550
561551 if (len > ZMS_DATA_IN_ATE_SIZE ) {
562- #ifdef CONFIG_ZMS_DATA_CRC
563- /* only compute CRC if data is to be stored outside of entry */
564- entry .data_crc = crc32_ieee (data , len );
565- #endif
552+ /* only compute CRC if len is greater than 8 bytes */
553+ if ( IS_ENABLED ( CONFIG_ZMS_DATA_CRC )) {
554+ entry .data_crc = crc32_ieee (data , len );
555+ }
566556 entry .offset = (uint32_t )SECTOR_OFFSET (fs -> data_wra );
567557 } else if ((len > 0 ) && (len <= ZMS_DATA_IN_ATE_SIZE )) {
568- /* Copy data into entry if data is sufficiently small */
558+ /* Copy data into entry for small data ( < 8B) */
569559 memcpy (& entry .data , data , len );
570560 }
571561
@@ -698,12 +688,10 @@ static int zms_sector_close(struct zms_fs *fs)
698688 struct zms_ate close_ate ;
699689 struct zms_ate garbage_ate ;
700690
701- /* Initialize all members to 0xff */
702- memset (& close_ate , 0xff , sizeof (struct zms_ate ));
703-
704691 close_ate .id = ZMS_HEAD_ID ;
705692 close_ate .len = 0U ;
706693 close_ate .offset = (uint32_t )SECTOR_OFFSET (fs -> ate_wra + fs -> ate_size );
694+ close_ate .metadata = 0xffffffff ;
707695 close_ate .cycle_cnt = fs -> sector_cycle ;
708696
709697 /* When we close the sector, we must write all non used ATE with
@@ -752,13 +740,11 @@ static int zms_add_gc_done_ate(struct zms_fs *fs)
752740{
753741 struct zms_ate gc_done_ate ;
754742
755- /* Initialize all members to 0xff */
756- memset (& gc_done_ate , 0xff , sizeof (struct zms_ate ));
757-
758743 LOG_DBG ("Adding gc done ate at %llx" , fs -> ate_wra );
759744 gc_done_ate .id = ZMS_HEAD_ID ;
760745 gc_done_ate .len = 0U ;
761746 gc_done_ate .offset = (uint32_t )SECTOR_OFFSET (fs -> data_wra );
747+ gc_done_ate .metadata = 0xffffffff ;
762748 gc_done_ate .cycle_cnt = fs -> sector_cycle ;
763749
764750 zms_ate_crc8_update (& gc_done_ate );
@@ -807,14 +793,12 @@ static int zms_add_empty_ate(struct zms_fs *fs, uint64_t addr)
807793 int rc = 0 ;
808794 uint64_t previous_ate_wra ;
809795
810- /* Initialize all members to 0 */
811- memset (& empty_ate , 0 , sizeof (struct zms_ate ));
812-
813796 addr &= ADDR_SECT_MASK ;
814797
815798 LOG_DBG ("Adding empty ate at %llx" , (uint64_t )(addr + fs -> sector_size - fs -> ate_size ));
816799 empty_ate .id = ZMS_HEAD_ID ;
817800 empty_ate .len = 0xffff ;
801+ empty_ate .offset = 0U ;
818802 empty_ate .metadata =
819803 FIELD_PREP (ZMS_MAGIC_NUMBER_MASK , ZMS_MAGIC_NUMBER ) | ZMS_DEFAULT_VERSION ;
820804
@@ -909,7 +893,7 @@ static int zms_get_sector_header(struct zms_fs *fs, uint64_t addr, struct zms_at
909893 * @retval 1 valid ATE with same ID found
910894 * @retval < 0 An error happened
911895 */
912- static int zms_find_ate_with_id (struct zms_fs * fs , zms_id_t id , uint64_t start_addr ,
896+ static int zms_find_ate_with_id (struct zms_fs * fs , uint32_t id , uint64_t start_addr ,
913897 uint64_t end_addr , struct zms_ate * ate , uint64_t * ate_addr )
914898{
915899 int rc ;
@@ -1060,10 +1044,10 @@ static int zms_gc(struct zms_fs *fs)
10601044 */
10611045 if (wlk_prev_addr == gc_prev_addr ) {
10621046 /* copy needed */
1063- LOG_DBG ("Moving %lld , len %d" , ( long long ) gc_ate .id , gc_ate .len );
1047+ LOG_DBG ("Moving %d , len %d" , gc_ate .id , gc_ate .len );
10641048
10651049 if (gc_ate .len > ZMS_DATA_IN_ATE_SIZE ) {
1066- /* Only copy Data with large enough len
1050+ /* Copy Data only when len > 8
10671051 * Otherwise, Data is already inside ATE
10681052 */
10691053 data_addr = (gc_prev_addr & ADDR_SECT_MASK );
@@ -1474,7 +1458,7 @@ int zms_mount(struct zms_fs *fs)
14741458 return 0 ;
14751459}
14761460
1477- ssize_t zms_write (struct zms_fs * fs , zms_id_t id , const void * data , size_t len )
1461+ ssize_t zms_write (struct zms_fs * fs , uint32_t id , const void * data , size_t len )
14781462{
14791463 int rc ;
14801464 size_t data_size ;
@@ -1614,12 +1598,12 @@ ssize_t zms_write(struct zms_fs *fs, zms_id_t id, const void *data, size_t len)
16141598 return rc ;
16151599}
16161600
1617- int zms_delete (struct zms_fs * fs , zms_id_t id )
1601+ int zms_delete (struct zms_fs * fs , uint32_t id )
16181602{
16191603 return zms_write (fs , id , NULL , 0 );
16201604}
16211605
1622- ssize_t zms_read_hist (struct zms_fs * fs , zms_id_t id , void * data , size_t len , uint32_t cnt )
1606+ ssize_t zms_read_hist (struct zms_fs * fs , uint32_t id , void * data , size_t len , uint32_t cnt )
16231607{
16241608 int rc ;
16251609 int prev_found = 0 ;
@@ -1716,7 +1700,7 @@ ssize_t zms_read_hist(struct zms_fs *fs, zms_id_t id, void *data, size_t len, ui
17161700 return rc ;
17171701}
17181702
1719- ssize_t zms_read (struct zms_fs * fs , zms_id_t id , void * data , size_t len )
1703+ ssize_t zms_read (struct zms_fs * fs , uint32_t id , void * data , size_t len )
17201704{
17211705 int rc ;
17221706
@@ -1729,7 +1713,7 @@ ssize_t zms_read(struct zms_fs *fs, zms_id_t id, void *data, size_t len)
17291713 return MIN (rc , len );
17301714}
17311715
1732- ssize_t zms_get_data_length (struct zms_fs * fs , zms_id_t id )
1716+ ssize_t zms_get_data_length (struct zms_fs * fs , uint32_t id )
17331717{
17341718 int rc ;
17351719
0 commit comments