Fixed some minor issues with did generation
- We need to clamp dids to 31-bits. We were clamping to 32-bits correctly, but we rely on dids fitting in 31-bits to fit them into our lfsr_data_t type. This does make our dids more dense when the mtree is near full, but keeping dids 31-bits (or bound to the file size type) also gives us more flexibility when it comes to deduplicating common leb128 operations. - We weren't using the right mask during collision resolution. This was just an oversight and an unimpactful fix. Also saved 4 bytes, which is probably the cost of storing the outdated constant in a nearby constant pool. We don't really care.
This commit is contained in:
@@ -7297,12 +7297,13 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
||||
// 4096/32 = 128, so a filesystem with a single mdir encodes dids in a
|
||||
// single byte.
|
||||
//
|
||||
lfs_size_t did = lfs_crc32c(0, path, strlen(path))
|
||||
// note we need to be careful to catch integer overflow
|
||||
& ((1 << lfs_min32(
|
||||
lfs_nlog2(lfsr_mtree_weight(lfs))
|
||||
+ lfs_nlog2(lfs->cfg->block_size/32),
|
||||
32)) - 1);
|
||||
// Note we also need to be careful to catch integer overflow.
|
||||
//
|
||||
lfs_size_t dmask = (1 << lfs_min32(
|
||||
lfs_nlog2(lfsr_mtree_weight(lfs))
|
||||
+ lfs_nlog2(lfs->cfg->block_size/32),
|
||||
32)) - 1;
|
||||
lfs_size_t did = lfs_crc32c(0, path, strlen(path)) & dmask;
|
||||
|
||||
// Check if we have a collision. If we do, search for the next
|
||||
// available did
|
||||
@@ -7319,7 +7320,7 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
||||
}
|
||||
|
||||
// try the next did
|
||||
did = (did + 1) & 0xfffffff;
|
||||
did = (did + 1) & dmask;
|
||||
}
|
||||
|
||||
// found a good did, now to commit to the mtree
|
||||
|
||||
Reference in New Issue
Block a user