/* This function returns %0 on success and a negative error code on failure.  */
static int recover_head(const struct ubifs_info *c, int lnum, int offs, void *sbuf)
/* This function returns %0 on success and a negative error code on failure.  */
static int recover_head(const struct ubifs_info *c, int lnum, int offs, void *sbuf)
{
	int len, err;
	if (c->min_io_size > 1)
		len = c->min_io_size;
	else
		len = 512;
	if (offs + len > c->leb_size)
		len = c->leb_size - offs;
	if (!len)
		return 0;
	err = ubi_read(c->ubi, lnum, sbuf, offs, len);
	if (err || !is_empty(sbuf, len)) {
		dbg_rcvry("cleaning head at %d:%d", lnum, offs);
		if (offs == 0)
			return ubifs_leb_unmap(c, lnum);
		err = ubi_read(c->ubi, lnum, sbuf, 0, offs);
		if (err)
			return err;
		return ubi_leb_change(c->ubi, lnum, sbuf, offs, UBI_UNKNOWN);
	}
	return 0;
}