nuttx/mtd: Add new functions part_isbad and part_markbad in mtd partition.

Signed-off-by: p-zhangliming1 <p-zhangliming1@xiaomi.com>
This commit is contained in:
p-zhangliming1 2023-03-29 18:10:56 +08:00 committed by Petro Karashchenko
parent 1e7678c58a
commit 4b2ae15069

View File

@ -116,6 +116,8 @@ static ssize_t part_write(FAR struct mtd_dev_s *dev, off_t offset,
#endif
static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd,
unsigned long arg);
static int part_isbad(FAR struct mtd_dev_s *dev, off_t block);
static int part_markbad(FAR struct mtd_dev_s *dev, off_t block);
/* File system methods */
@ -494,6 +496,60 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
return ret;
}
/****************************************************************************
* Name: part_isbad
*
* Description:
* Check bad block for the specified block number.
*
****************************************************************************/
static int part_isbad(FAR struct mtd_dev_s *dev, off_t block)
{
FAR struct mtd_partition_s *priv = (FAR struct mtd_partition_s *)dev;
DEBUGASSERT(priv);
/* Does the underlying MTD device support the isbad method? */
if (priv->parent->isbad)
{
return priv->parent->isbad(priv->parent, block +
priv->firstblock / priv->blkpererase);
}
/* The underlying MTD driver does not support the isbad() method */
return -ENOSYS;
}
/****************************************************************************
* Name: part_markbad
*
* Description:
* Mark bad block for the specified block number.
*
****************************************************************************/
static int part_markbad(FAR struct mtd_dev_s *dev, off_t block)
{
FAR struct mtd_partition_s *priv = (FAR struct mtd_partition_s *)dev;
DEBUGASSERT(priv);
/* Does the underlying MTD device support the markbad method? */
if (priv->parent->markbad)
{
return priv->parent->markbad(priv->parent, block +
priv->firstblock / priv->blkpererase);
}
/* The underlying MTD driver does not support the markbad() method */
return -ENOSYS;
}
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_PROCFS_EXCLUDE_PARTITIONS)
/****************************************************************************
@ -856,6 +912,8 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd,
part->child.bwrite = part_bwrite;
part->child.read = mtd->read ? part_read : NULL;
part->child.ioctl = part_ioctl;
part->child.isbad = part_isbad;
part->child.markbad = part_markbad;
#ifdef CONFIG_MTD_BYTE_WRITE
part->child.write = mtd->write ? part_write : NULL;
#endif