Initial groundwork for rbyd trees
- primitive lfs_rbyd_fetch
- primitive lfs_rbyd_commit
- tag reading/progging and encoding machinery
The tag encoding scheme here uses pairs of leb128s, encoding either
a normal tag:
iiii iiiiiii iiiiiTT TTTTTTt ttttt0v
^--------^------^-^- 16-bit id
'------|-|- 8-bit type2
'-|- 6-bit type1
'- valid bit
llll lllllll lllllll lllllll lllllll
^- n-bit length
Or an alt pointer:
wwww wwwwwww wwwwwww wwwwwww wwwcd1v
^^^-^- 28-bit weight
'|-|- color bit
'-|- direction bit
'- valid bit
jjjj jjjjjjj jjjjjjj jjjjjjj jjjjjjj
^- n-bit jump
Note that two bits overlap the alt pointer dir/color encoding, this
is actually not a problem at all since some tags (crcs/fcrcs) don't
participate in the rbyd tree and can use these bits.
There's a number of benefits to using leb128s, which should probably
be written about, most notably is the abstraction of the device's
word-size. The "n-bits" above can be whatever word size works on the
device, trading off code-size for storage capabilities without breaking
compatibility with other devices. This will eventually be negotiated via
the superblock.
This commit is contained in:
+22
@@ -212,6 +212,28 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
|
||||
return lfs_frombe32(a);
|
||||
}
|
||||
|
||||
// Convert to/from 32-bit little-endian
|
||||
static inline void lfs_tole32_(uint32_t word, void *buffer) {
|
||||
((uint8_t*)buffer)[0] = word >> 0;
|
||||
((uint8_t*)buffer)[1] = word >> 8;
|
||||
((uint8_t*)buffer)[2] = word >> 16;
|
||||
((uint8_t*)buffer)[3] = word >> 24;
|
||||
}
|
||||
|
||||
static inline uint32_t lfs_fromle32_(const void *buffer) {
|
||||
return (((uint8_t*)buffer)[0] << 0)
|
||||
| (((uint8_t*)buffer)[1] << 8)
|
||||
| (((uint8_t*)buffer)[2] << 16)
|
||||
| (((uint8_t*)buffer)[3] << 24);
|
||||
}
|
||||
|
||||
// Convert to/from leb128 encoding
|
||||
ssize_t lfs_toleb128(uint32_t word, void *buffer, size_t size);
|
||||
|
||||
ssize_t lfs_fromleb128(uint32_t *word, const void *buffer, size_t size);
|
||||
|
||||
|
||||
|
||||
// Calculate CRC-32 with polynomial = 0x04c11db7
|
||||
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user