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 #endif
static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd,
unsigned long arg); 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 */ /* File system methods */
@ -494,6 +496,60 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
return ret; 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) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_PROCFS_EXCLUDE_PARTITIONS)
/**************************************************************************** /****************************************************************************
@ -851,21 +907,23 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd,
* nullified by kmm_zalloc). * nullified by kmm_zalloc).
*/ */
part->child.erase = part_erase; part->child.erase = part_erase;
part->child.bread = part_bread; part->child.bread = part_bread;
part->child.bwrite = part_bwrite; part->child.bwrite = part_bwrite;
part->child.read = mtd->read ? part_read : NULL; part->child.read = mtd->read ? part_read : NULL;
part->child.ioctl = part_ioctl; part->child.ioctl = part_ioctl;
part->child.isbad = part_isbad;
part->child.markbad = part_markbad;
#ifdef CONFIG_MTD_BYTE_WRITE #ifdef CONFIG_MTD_BYTE_WRITE
part->child.write = mtd->write ? part_write : NULL; part->child.write = mtd->write ? part_write : NULL;
#endif #endif
part->child.name = "part"; part->child.name = "part";
part->parent = mtd; part->parent = mtd;
part->firstblock = erasestart * blkpererase; part->firstblock = erasestart * blkpererase;
part->neraseblocks = eraseend - erasestart; part->neraseblocks = eraseend - erasestart;
part->blocksize = geo.blocksize; part->blocksize = geo.blocksize;
part->blkpererase = blkpererase; part->blkpererase = blkpererase;
#ifdef CONFIG_MTD_PARTITION_NAMES #ifdef CONFIG_MTD_PARTITION_NAMES
strlcpy(part->name, "(noname)", sizeof(part->name)); strlcpy(part->name, "(noname)", sizeof(part->name));