/* This function is used by repack to count the number of BPDT and S-BPDT entries that are present. It frees the current buffers used by the entries and allocates fresh buffers that can be used for repacking. Returns BPDT entries which are empty and need to be filled in.  */
static void __bpdt_reset(struct buffer *b, size_t count, size_t size)
/* This function is used by repack to count the number of BPDT and S-BPDT entries that are present. It frees the current buffers used by the entries and allocates fresh buffers that can be used for repacking. Returns BPDT entries which are empty and need to be filled in.  */
static void __bpdt_reset(struct buffer *b, size_t count, size_t size)
{
	size_t bpdt_size = BPDT_HEADER_SIZE + count * BPDT_ENTRY_SIZE;
	assert(size >= bpdt_size);
	if (buffer_size(b) != size) {
		struct buffer temp;
		alloc_buffer(&temp, size, b->name);
		memcpy(buffer_get(&temp), buffer_get(b), buffer_size(b));
		buffer_delete(b);
		*b = temp;
	}
	struct bpdt *bpdt = buffer_get(b);
	uint8_t *ptr = (uint8_t *)&bpdt->e[0];
	size_t entries_size = BPDT_ENTRY_SIZE * count;
	memset(ptr, 0, entries_size);
	memset(ptr + entries_size, 0xFF, size - bpdt_size);
	bpdt->h.descriptor_count = count;
}