blk/mtdoutstream: remove mtd bytewrite support, readback before update

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
buxiasen 2024-11-08 20:51:23 +08:00 committed by Xiang Xiao
parent d6c746e88d
commit 2433094ebd
2 changed files with 70 additions and 104 deletions

View file

@ -104,11 +104,14 @@ static int blkoutstream_puts(FAR struct lib_outstream_s *self,
} }
else if (remain < sectorsize) else if (remain < sectorsize)
{ {
/* Set content to all 0 before caching, /* Read sector back to keep as more as possible old data */
* so no random content will be flushed
*/ ret = inode->u.i_bops->read(inode, stream->cache, sector, 1);
if (ret < 0)
{
return ret;
}
memset(stream->cache, 0, sectorsize);
memcpy(stream->cache, ptr, remain); memcpy(stream->cache, ptr, remain);
self->nput += remain; self->nput += remain;
remain = 0; remain = 0;

View file

@ -58,12 +58,6 @@ static int mtdoutstream_flush(FAR struct lib_outstream_s *self)
if (self->nput % erasesize > 0) if (self->nput % erasesize > 0)
{ {
#ifdef CONFIG_MTD_BYTE_WRITE
/* if byte write, flush won't be needed */
if (inode->u.i_mtd->write == NULL)
#endif
{
size_t sblock = self->nput / erasesize; size_t sblock = self->nput / erasesize;
ret = MTD_ERASE(inode->u.i_mtd, sblock, 1); ret = MTD_ERASE(inode->u.i_mtd, sblock, 1);
@ -75,7 +69,6 @@ static int mtdoutstream_flush(FAR struct lib_outstream_s *self)
ret = MTD_BWRITE(inode->u.i_mtd, sblock * nblkpererase, ret = MTD_BWRITE(inode->u.i_mtd, sblock * nblkpererase,
nblkpererase, stream->cache); nblkpererase, stream->cache);
} }
}
return ret; return ret;
} }
@ -101,32 +94,6 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
return -ENOSPC; return -ENOSPC;
} }
#ifdef CONFIG_MTD_BYTE_WRITE
if (inode->u.i_mtd->write != NULL)
{
size_t sblock = (self->nput + erasesize - 1) / erasesize;
size_t eblock = (self->nput + len + erasesize - 1) / erasesize;
if (sblock != eblock)
{
ret = MTD_ERASE(inode->u.i_mtd, sblock, eblock - sblock);
if (ret < 0)
{
return ret;
}
}
ret = MTD_WRITE(inode->u.i_mtd, self->nput, len, buf);
if (ret < 0)
{
return ret;
}
self->nput += len;
}
else
#endif
{
while (remain > 0) while (remain > 0)
{ {
size_t sblock = self->nput / erasesize; size_t sblock = self->nput / erasesize;
@ -162,11 +129,13 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
} }
else if (remain < erasesize) else if (remain < erasesize)
{ {
/* erase content to all 0 before caching, ret = MTD_READ(stream->inode->u.i_mtd, sblock * erasesize,
* so no random content will be flushed erasesize, stream->cache);
*/ if (ret < 0)
{
return ret;
}
memset(stream->cache, 0, erasesize);
memcpy(stream->cache, ptr, remain); memcpy(stream->cache, ptr, remain);
self->nput += remain; self->nput += remain;
remain = 0; remain = 0;
@ -194,7 +163,6 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
remain -= copyin; remain -= copyin;
} }
} }
}
return len; return len;
} }
@ -295,17 +263,12 @@ int lib_mtdoutstream_open(FAR struct lib_mtdoutstream_s *stream,
return -EINVAL; return -EINVAL;
} }
#ifdef CONFIG_MTD_BYTE_WRITE
if (node->u.i_mtd->write == NULL)
#endif
{
stream->cache = lib_malloc(stream->geo.erasesize); stream->cache = lib_malloc(stream->geo.erasesize);
if (stream->cache == NULL) if (stream->cache == NULL)
{ {
close_mtddriver(node); close_mtddriver(node);
return -ENOMEM; return -ENOMEM;
} }
}
stream->inode = node; stream->inode = node;
stream->common.putc = mtdoutstream_putc; stream->common.putc = mtdoutstream_putc;