/* This function calculates and returns amount of FS space available for use.  */
long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs)
/* This function calculates and returns amount of FS space available for use.  */
long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs)
{
	int subtract_lebs;
	long long available;
	available = c->main_bytes - c->lst.total_used;
	subtract_lebs = min_idx_lebs;
	subtract_lebs += 1;
	subtract_lebs += c->jhead_cnt - 1;
	subtract_lebs += 1;
	available -= (long long)subtract_lebs * c->leb_size;
	available -= c->lst.total_dead;
	available -= c->lst.total_dark;
	if (c->lst.idx_lebs > min_idx_lebs) {
		subtract_lebs = c->lst.idx_lebs - min_idx_lebs;
		available -= subtract_lebs * c->dark_wm;
	}
	return available > 0 ? available : 0;
}