Skip to content

Commit befd466

Browse files
committed
Revert "[nrf fromlist] zms: Initial support for 64 bit IDs"
This reverts commit 73fe1ee. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent b796021 commit befd466

File tree

4 files changed

+31
-94
lines changed

4 files changed

+31
-94
lines changed

include/zephyr/fs/zms.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ struct zms_fs {
7777
* @{
7878
*/
7979

80-
/**
81-
* @brief ID type used in the ZMS API.
82-
*
83-
* @note The width of this type depends on @kconfig{CONFIG_ZMS_ID_64BIT}.
84-
*/
85-
#if CONFIG_ZMS_ID_64BIT
86-
typedef uint64_t zms_id_t;
87-
#else
88-
typedef uint32_t zms_id_t;
89-
#endif
90-
9180
/**
9281
* @brief Mount a ZMS file system onto the device specified in `fs`.
9382
*
@@ -138,7 +127,7 @@ int zms_clear(struct zms_fs *fs);
138127
* @retval -EINVAL if `len` is invalid.
139128
* @retval -ENOSPC if no space is left on the device.
140129
*/
141-
ssize_t zms_write(struct zms_fs *fs, zms_id_t id, const void *data, size_t len);
130+
ssize_t zms_write(struct zms_fs *fs, uint32_t id, const void *data, size_t len);
142131

143132
/**
144133
* @brief Delete an entry from the file system
@@ -151,7 +140,7 @@ ssize_t zms_write(struct zms_fs *fs, zms_id_t id, const void *data, size_t len);
151140
* @retval -ENXIO if there is a device error.
152141
* @retval -EIO if there is a memory read/write error.
153142
*/
154-
int zms_delete(struct zms_fs *fs, zms_id_t id);
143+
int zms_delete(struct zms_fs *fs, uint32_t id);
155144

156145
/**
157146
* @brief Read an entry from the file system.
@@ -169,7 +158,7 @@ int zms_delete(struct zms_fs *fs, zms_id_t id);
169158
* @retval -EIO if there is a memory read/write error.
170159
* @retval -ENOENT if there is no entry with the given `id`.
171160
*/
172-
ssize_t zms_read(struct zms_fs *fs, zms_id_t id, void *data, size_t len);
161+
ssize_t zms_read(struct zms_fs *fs, uint32_t id, void *data, size_t len);
173162

174163
/**
175164
* @brief Read a history entry from the file system.
@@ -189,7 +178,7 @@ ssize_t zms_read(struct zms_fs *fs, zms_id_t id, void *data, size_t len);
189178
* @retval -EIO if there is a memory read/write error.
190179
* @retval -ENOENT if there is no entry with the given `id` and history counter.
191180
*/
192-
ssize_t zms_read_hist(struct zms_fs *fs, zms_id_t id, void *data, size_t len, uint32_t cnt);
181+
ssize_t zms_read_hist(struct zms_fs *fs, uint32_t id, void *data, size_t len, uint32_t cnt);
193182

194183
/**
195184
* @brief Gets the length of the data that is stored in an entry with a given `id`
@@ -204,7 +193,7 @@ ssize_t zms_read_hist(struct zms_fs *fs, zms_id_t id, void *data, size_t len, ui
204193
* @retval -EIO if there is a memory read/write error.
205194
* @retval -ENOENT if there is no entry with the given id and history counter.
206195
*/
207-
ssize_t zms_get_data_length(struct zms_fs *fs, zms_id_t id);
196+
ssize_t zms_get_data_length(struct zms_fs *fs, uint32_t id);
208197

209198
/**
210199
* @brief Calculate the available free space in the file system.

subsys/fs/zms/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ config ZMS
1515

1616
if ZMS
1717

18-
config ZMS_ID_64BIT
19-
bool "64 bit ZMS IDs"
20-
help
21-
When this option is true, the `zms_id_t` values passed to ZMS APIs will be 64 bit,
22-
as opposed to the default 32 bit.
23-
This option will also change the format of allocation table entries (ATEs) in memory
24-
to accommodate larger IDs. Currently, this will make ZMS unable to mount an existing
25-
file system if it has been initialized with a different ATE format.
26-
2718
config ZMS_LOOKUP_CACHE
2819
bool "ZMS lookup cache"
2920
help
@@ -42,7 +33,6 @@ config ZMS_LOOKUP_CACHE_SIZE
4233

4334
config ZMS_DATA_CRC
4435
bool "ZMS data CRC"
45-
depends on !ZMS_ID_64BIT
4636

4737
config ZMS_CUSTOMIZE_BLOCK_SIZE
4838
bool "Customize the size of the buffer used internally for reads and writes"

subsys/fs/zms/zms.c

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
503493
static 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
*/
516506
static 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

subsys/fs/zms/zms_priv.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@
2828
#endif
2929

3030
#define ZMS_LOOKUP_CACHE_NO_ADDR GENMASK64(63, 0)
31+
#define ZMS_HEAD_ID GENMASK(31, 0)
3132

3233
#define ZMS_VERSION_MASK GENMASK(7, 0)
3334
#define ZMS_GET_VERSION(x) FIELD_GET(ZMS_VERSION_MASK, x)
3435
#define ZMS_DEFAULT_VERSION 1
36+
#define ZMS_MAGIC_NUMBER 0x42 /* murmur3a hash of "ZMS" (MSB) */
3537
#define ZMS_MAGIC_NUMBER_MASK GENMASK(15, 8)
3638
#define ZMS_GET_MAGIC_NUMBER(x) FIELD_GET(ZMS_MAGIC_NUMBER_MASK, x)
3739
#define ZMS_MIN_ATE_NUM 5
3840

3941
#define ZMS_INVALID_SECTOR_NUM -1
42+
#define ZMS_DATA_IN_ATE_SIZE 8
4043

4144
/**
4245
* @ingroup zms_data_structures
4346
* ZMS Allocation Table Entry (ATE) structure
44-
*
45-
* @note This structure depends on @kconfig{CONFIG_ZMS_ID_64BIT}.
4647
*/
4748
struct zms_ate {
4849
/** crc8 check of the entry */
@@ -51,8 +52,6 @@ struct zms_ate {
5152
uint8_t cycle_cnt;
5253
/** data len within sector */
5354
uint16_t len;
54-
55-
#if !defined(CONFIG_ZMS_ID_64BIT)
5655
/** data id */
5756
uint32_t id;
5857
union {
@@ -76,31 +75,6 @@ struct zms_ate {
7675
};
7776
};
7877
};
79-
#else
80-
/** data id */
81-
uint64_t id;
82-
union {
83-
/** data field used to store small sized data */
84-
uint8_t data[4];
85-
/** data offset within sector */
86-
uint32_t offset;
87-
/** Used to store metadata information such as storage version. */
88-
uint32_t metadata;
89-
};
90-
#endif /* CONFIG_ZMS_ID_64BIT */
91-
9278
} __packed;
9379

94-
#define ZMS_DATA_IN_ATE_SIZE SIZEOF_FIELD(struct zms_ate, data)
95-
96-
#if !defined(CONFIG_ZMS_ID_64BIT)
97-
#define ZMS_HEAD_ID GENMASK(31, 0)
98-
#define ZMS_MAGIC_NUMBER 0x42 /* murmur3a hash of "ZMS" (MSB) */
99-
100-
#else
101-
#define ZMS_HEAD_ID GENMASK64(63, 0)
102-
#define ZMS_MAGIC_NUMBER 0xb8 /* murmur3a hash of "ZMS64" (MSB) */
103-
104-
#endif /* CONFIG_ZMS_ID_64BIT */
105-
10680
#endif /* __ZMS_PRIV_H_ */

0 commit comments

Comments
 (0)