blk/mtdoutstream: remove mtd bytewrite support, readback before update
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
parent
d6c746e88d
commit
2433094ebd
2 changed files with 70 additions and 104 deletions
|
@ -104,11 +104,14 @@ static int blkoutstream_puts(FAR struct lib_outstream_s *self,
|
|||
}
|
||||
else if (remain < sectorsize)
|
||||
{
|
||||
/* Set content to all 0 before caching,
|
||||
* so no random content will be flushed
|
||||
*/
|
||||
/* Read sector back to keep as more as possible old data */
|
||||
|
||||
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);
|
||||
self->nput += remain;
|
||||
remain = 0;
|
||||
|
|
|
@ -58,12 +58,6 @@ static int mtdoutstream_flush(FAR struct lib_outstream_s *self)
|
|||
|
||||
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;
|
||||
|
||||
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,
|
||||
nblkpererase, stream->cache);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -101,32 +94,6 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
|
|||
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)
|
||||
{
|
||||
size_t sblock = self->nput / erasesize;
|
||||
|
@ -162,11 +129,13 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
|
|||
}
|
||||
else if (remain < erasesize)
|
||||
{
|
||||
/* erase content to all 0 before caching,
|
||||
* so no random content will be flushed
|
||||
*/
|
||||
ret = MTD_READ(stream->inode->u.i_mtd, sblock * erasesize,
|
||||
erasesize, stream->cache);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(stream->cache, 0, erasesize);
|
||||
memcpy(stream->cache, ptr, remain);
|
||||
self->nput += remain;
|
||||
remain = 0;
|
||||
|
@ -194,7 +163,6 @@ static int mtdoutstream_puts(FAR struct lib_outstream_s *self,
|
|||
remain -= copyin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
@ -295,17 +263,12 @@ int lib_mtdoutstream_open(FAR struct lib_mtdoutstream_s *stream,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MTD_BYTE_WRITE
|
||||
if (node->u.i_mtd->write == NULL)
|
||||
#endif
|
||||
{
|
||||
stream->cache = lib_malloc(stream->geo.erasesize);
|
||||
if (stream->cache == NULL)
|
||||
{
|
||||
close_mtddriver(node);
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
stream->inode = node;
|
||||
stream->common.putc = mtdoutstream_putc;
|
||||
|
|
Loading…
Reference in a new issue