forked from len0rd/rockbox
buflib: Switch from term "cookie" to "metadata"
The documentation of buflib first mentions metadata and then changes to "cookie" without explaining it. Fix it by sticking to metadata. Change-Id: I0b36b18f4f2590132901c10326481975f8b9b9da
This commit is contained in:
parent
66df5f3891
commit
bce72e6f2c
1 changed files with 13 additions and 13 deletions
|
|
@ -55,7 +55,7 @@
|
||||||
* to find the start of the character array (and therefore the start of the
|
* to find the start of the character array (and therefore the start of the
|
||||||
* entire block) when only the handle or payload start is known.
|
* entire block) when only the handle or payload start is known.
|
||||||
*
|
*
|
||||||
* UPDATE BUFLIB_ALLOC_OVERHEAD (buflib.h) WHEN THIS COOKIE CHANGES!
|
* UPDATE BUFLIB_ALLOC_OVERHEAD (buflib.h) WHEN THE METADATA CHANGES!
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->|
|
* |<- alloc block #1 ->|<- unalloc block ->|<- alloc block #2 ->|<-handle table->|
|
||||||
|
|
@ -66,7 +66,7 @@
|
||||||
* C - pointer to struct buflib_callbacks
|
* C - pointer to struct buflib_callbacks
|
||||||
* c - variable sized string identifier
|
* c - variable sized string identifier
|
||||||
* L2 - second length marker for string identifier
|
* L2 - second length marker for string identifier
|
||||||
* crc - crc32 protecting buflib cookie integrity
|
* crc - crc32 protecting buflib metadata integrity
|
||||||
* X - actual payload
|
* X - actual payload
|
||||||
* Y - unallocated space
|
* Y - unallocated space
|
||||||
*
|
*
|
||||||
|
|
@ -251,12 +251,12 @@ move_block(struct buflib_context* ctx, union buflib_data* block, int shift)
|
||||||
union buflib_data *new_block, *tmp = block[1].handle, *crc_slot;
|
union buflib_data *new_block, *tmp = block[1].handle, *crc_slot;
|
||||||
struct buflib_callbacks *ops = block[2].ops;
|
struct buflib_callbacks *ops = block[2].ops;
|
||||||
crc_slot = (union buflib_data*)tmp->alloc - 1;
|
crc_slot = (union buflib_data*)tmp->alloc - 1;
|
||||||
int cookie_size = (crc_slot - block)*sizeof(union buflib_data);
|
const int metadata_size = (crc_slot - block)*sizeof(union buflib_data);
|
||||||
uint32_t crc = crc_32((void *)block, cookie_size, 0xffffffff);
|
uint32_t crc = crc_32((void *)block, metadata_size, 0xffffffff);
|
||||||
|
|
||||||
/* check for cookie validity */
|
/* check for metadata validity */
|
||||||
if (crc != crc_slot->crc)
|
if (crc != crc_slot->crc)
|
||||||
buflib_panic(ctx, "buflib cookie corrupted, crc: 0x%08x, expected: 0x%08x",
|
buflib_panic(ctx, "buflib metadata corrupted, crc: 0x%08x, expected: 0x%08x",
|
||||||
(unsigned int)crc, (unsigned int)crc_slot->crc);
|
(unsigned int)crc, (unsigned int)crc_slot->crc);
|
||||||
|
|
||||||
if (!IS_MOVABLE(block))
|
if (!IS_MOVABLE(block))
|
||||||
|
|
@ -827,7 +827,7 @@ bool
|
||||||
buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t new_size)
|
buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t new_size)
|
||||||
{
|
{
|
||||||
union buflib_data *crc_slot;
|
union buflib_data *crc_slot;
|
||||||
int cookie_size;
|
int size_for_crc32;
|
||||||
char* oldstart = buflib_get_data(ctx, handle);
|
char* oldstart = buflib_get_data(ctx, handle);
|
||||||
char* newstart = new_start;
|
char* newstart = new_start;
|
||||||
char* newend = newstart + new_size;
|
char* newend = newstart + new_size;
|
||||||
|
|
@ -873,10 +873,10 @@ buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t ne
|
||||||
block = new_block;
|
block = new_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update crc of the cookie */
|
/* update crc of the metadata */
|
||||||
crc_slot = (union buflib_data*)new_block[1].handle->alloc - 1;
|
crc_slot = (union buflib_data*)new_block[1].handle->alloc - 1;
|
||||||
cookie_size = (crc_slot - new_block)*sizeof(union buflib_data);
|
size_for_crc32 = (crc_slot - new_block)*sizeof(union buflib_data);
|
||||||
crc_slot->crc = crc_32((void *)new_block, cookie_size, 0xffffffff);
|
crc_slot->crc = crc_32((void *)new_block, size_for_crc32, 0xffffffff);
|
||||||
|
|
||||||
/* Now deal with size changes that create free blocks after the allocation */
|
/* Now deal with size changes that create free blocks after the allocation */
|
||||||
if (old_next_block != new_next_block)
|
if (old_next_block != new_next_block)
|
||||||
|
|
@ -919,7 +919,7 @@ void *buflib_get_data(struct buflib_context *ctx, int handle)
|
||||||
void buflib_check_valid(struct buflib_context *ctx)
|
void buflib_check_valid(struct buflib_context *ctx)
|
||||||
{
|
{
|
||||||
union buflib_data *crc_slot;
|
union buflib_data *crc_slot;
|
||||||
int cookie_size;
|
int metadata_size;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
|
|
||||||
for(union buflib_data* this = ctx->buf_start;
|
for(union buflib_data* this = ctx->buf_start;
|
||||||
|
|
@ -931,8 +931,8 @@ void buflib_check_valid(struct buflib_context *ctx)
|
||||||
|
|
||||||
crc_slot = (union buflib_data*)
|
crc_slot = (union buflib_data*)
|
||||||
((union buflib_data*)this[1].handle)->alloc - 1;
|
((union buflib_data*)this[1].handle)->alloc - 1;
|
||||||
cookie_size = (crc_slot - this)*sizeof(union buflib_data);
|
metadata_size = (crc_slot - this)*sizeof(union buflib_data);
|
||||||
crc = crc_32((void *)this, cookie_size, 0xffffffff);
|
crc = crc_32((void *)this, metadata_size, 0xffffffff);
|
||||||
|
|
||||||
if (crc != crc_slot->crc)
|
if (crc != crc_slot->crc)
|
||||||
buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x",
|
buflib_panic(ctx, "crc mismatch: 0x%08x, expected: 0x%08x",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue