/* Description: Reads @count bytes from @bdev into @buffer. Returns number of bytes read on success, 0 on error.  */
static size_t read_lba(struct block_device *bdev, u64 lba, u8 *buffer, size_t count)
/* Description: Reads @count bytes from @bdev into @buffer. Returns number of bytes read on success, 0 on error.  */
static size_t read_lba(struct block_device *bdev, u64 lba, u8 *buffer, size_t count)
{
	size_t totalreadcount = 0;
	sector_t n = lba * (bdev_logical_block_size(bdev) / 512);
	if (!bdev || !buffer || lba > last_lba(bdev))
                return 0;
	while (count) {
		int copied = 512;
		Sector sect;
		unsigned char *data = read_dev_sector(bdev, n++, &sect);
		if (!data)
			break;
		if (copied > count)
			copied = count;
		memcpy(buffer, data, copied);
		put_dev_sector(sect);
		buffer += copied;
		totalreadcount +=copied;
		count -= copied;
	}
	return totalreadcount;
}