/* This function calculates how much "real data" is stored in @buf and returnes the length. Continuous 0xFF bytes at the end of the buffer are not considered as "real data".  */
int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length)
/* This function calculates how much "real data" is stored in @buf and returnes the length. Continuous 0xFF bytes at the end of the buffer are not considered as "real data".  */
int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length)
{
	int i;
	ubi_assert(!(length & (ubi->min_io_size - 1)));
	for (i = length - 1; i >= 0; i--)
		if (((const uint8_t *)buf)[i] != 0xFF)
			break;
	length = ALIGN(i + 1, ubi->min_io_size);
	return length;
}