/* This function finds the next empty LEB in the ltab starting from @lnum. If a an empty LEB is found it is returned in @lnum and the function returns %0. Otherwise the function returns -ENOSPC. Note however, that LPT is designed never to run out of space.  */
static int alloc_lpt_leb(struct ubifs_info *c, int *lnum)
/* This function finds the next empty LEB in the ltab starting from @lnum. If a an empty LEB is found it is returned in @lnum and the function returns %0. Otherwise the function returns -ENOSPC. Note however, that LPT is designed never to run out of space.  */
static int alloc_lpt_leb(struct ubifs_info *c, int *lnum)
{
	int i, n;
	n = *lnum - c->lpt_first + 1;
	for (i = n; i < c->lpt_lebs; i++) {
		if (c->ltab[i].tgc || c->ltab[i].cmt)
			continue;
		if (c->ltab[i].free == c->leb_size) {
			c->ltab[i].cmt = 1;
			*lnum = i + c->lpt_first;
			return 0;
		}
	}
	for (i = 0; i < n; i++) {
		if (c->ltab[i].tgc || c->ltab[i].cmt)
			continue;
		if (c->ltab[i].free == c->leb_size) {
			c->ltab[i].cmt = 1;
			*lnum = i + c->lpt_first;
			return 0;
		}
	}
	return -ENOSPC;
}