ftl:remove erase buffer for mtd device without erase interface

When there's no erase function for mtd, we decide if we
need erase_buffer based on this:

1. If we've got bad block marking, we still need the erase buffer.
   If a write fails, it's used to read back the entire bad block's
   contents before writing to a new block.
2. If we don't have bad block marking, the erase buffer isn't
   needed and can be skipped.

Signed-off-by: jingfei <jingfei@xiaomi.com>
This commit is contained in:
jingfei 2025-05-27 12:34:54 +08:00 committed by Xiang Xiao
parent e823681091
commit 152ea6c4bd

View file

@ -561,6 +561,18 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
int nbytes;
int ret;
if (dev->mtd->erase == NULL && dev->lptable == NULL)
{
ret = MTD_BWRITE(dev->mtd, startblock, nblocks, buffer);
if (ret != nblocks)
{
ferr("ERROR: Direct write block %" PRIdOFF " failed: %d\n",
startblock, ret);
}
return ret;
}
if (dev->oflags & O_DIRECT)
{
/* Direct write mode */