/* Allocate buffer for bpdt header, entries and all sub-partition content. Returns offset in data where BPDT ends.  */
static size_t alloc_bpdt_buffer(void *data, size_t size, size_t offset, struct buffer *b, const char *name)
/* Allocate buffer for bpdt header, entries and all sub-partition content. Returns offset in data where BPDT ends.  */
static size_t alloc_bpdt_buffer(void *data, size_t size, size_t offset, struct buffer *b, const char *name)
{
	struct bpdt_header bpdt_header;
	assert((offset + BPDT_HEADER_SIZE) < size);
	bpdt_read_header((uint8_t *)data + offset, &bpdt_header, name);
	alloc_buffer(b, get_bpdt_size(&bpdt_header), name);
	struct bpdt *bpdt = buffer_get(b);
	memcpy(&bpdt->h, &bpdt_header, BPDT_HEADER_SIZE);
	if (bpdt->h.descriptor_count == 0)
		return (offset + BPDT_HEADER_SIZE);
	assert((offset + get_bpdt_size(&bpdt->h)) < size);
	bpdt_read_entries((uint8_t *)data + offset + BPDT_HEADER_SIZE, bpdt,
			  name);
	return read_subpart_buf(data, size, &bpdt->e[0],
				bpdt->h.descriptor_count);
}