[PATCH v3 2/3] ubifs: add ubifs_fixup_free_space()

Artem Bityutskiy dedekind1 at gmail.com
Fri May 6 11:02:48 EDT 2011


On Thu, 2011-05-05 at 16:33 -0400, Matthew L. Creech wrote:
> +/**
> + * fixup_leb_free_space - remap/unmap a LEB containing free space.
> + * @c: UBIFS file-system description object
> + * @lnum: LEB number
> + * @len: number of used bytes in LEB (starting at offset 0)
> + *
> + * This function reads the contents of the given LEB, then remaps it to a
> + * new PEB, so that any empty pages are actually erased on flash (rather than
> + * being just all-0xff real data).  If the LEB is completely empty, it is
> + * simply unmappped.
> + */
> +static int fixup_leb_free_space(struct ubifs_info *c, int lnum, int len)
> +{
> +	int err = 0, aligned_len;
> +	void *sbuf = c->sbuf;
> +
> +	ubifs_assert(len >= 0);
> +	ubifs_assert(len % c->min_io_size == 0);

So if this is true.

> +	ubifs_assert(len < c->leb_size);
> +
> +	if (len == 0) {
> +		/* LEB has no valid data, unmap it (no-op if it's unused) */
> +		dbg_mnt("unmap empty LEB %d", lnum);
> +		return ubi_leb_unmap(c->ubi, lnum);
> +	}
> +
> +	dbg_mnt("fixup partially-empty LEB %d (len %d)", lnum, len);
> +
> +	/* Read the existing valid data for this LEB */
> +	err = ubi_read(c->ubi, lnum, sbuf, 0, len);
> +	if (err && err != -EBADMSG)
> +		return err;
> +
> +	/* Pad if necessary */
> +	aligned_len = ALIGN(len, c->min_io_size);
> +	if (aligned_len > len) {

This will be always false and the below code can be removed, right?

> +		int pad_len = aligned_len - ALIGN(len, 8);
> +
> +		if (pad_len > 0) {
> +			void *buf = sbuf + aligned_len - pad_len;
> +
> +			ubifs_pad(c, buf, pad_len);
> +		}
> +	}
> +

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)




More information about the linux-mtd mailing list