This is an automated email from the ASF dual-hosted git repository.
ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c54c9395a5 Revert "drivrs/mtd/filemtd.c: add block device MTD
interface. Block MTD interface allows using block device directly as MTD
instead of having to use file-system in between. NOTE that this provides the
opposite capability of FTL which will let you use an MTD interface directly as
a block device."
c54c9395a5 is described below
commit c54c9395a572c0c68b2ca6bf028e7a09daa41d52
Author: Xiang Xiao <[email protected]>
AuthorDate: Sat Feb 18 07:48:46 2023 +0800
Revert "drivrs/mtd/filemtd.c: add block device MTD interface. Block MTD
interface allows using block device directly as MTD instead of having to use
file-system in between. NOTE that this provides the opposite capability of FTL
which will let you use an MTD interface directly as a block device."
since filemtd can handle not only char device, but also block device.
This reverts commit 5ef548677a7f93f18503105c2d9d0a42d155181c.
---
drivers/mtd/filemtd.c | 97 +++++++++++++++----------------------------------
include/nuttx/mtd/mtd.h | 29 ---------------
2 files changed, 30 insertions(+), 96 deletions(-)
diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c
index 1048461d37..36e2d7e9cf 100644
--- a/drivers/mtd/filemtd.c
+++ b/drivers/mtd/filemtd.c
@@ -700,26 +700,44 @@ static int mtd_loop_ioctl(FAR struct file *filep, int cmd,
****************************************************************************/
/****************************************************************************
- * Name: blockmtd_initialize
+ * Name: filemtd_initialize
*
* Description:
- * Create and initialize a BLOCK MTD device instance.
+ * Create and initialize a FILE MTD device instance.
*
* Input Parameters:
- * path - Path name of the block device backing the MTD device
+ * path - Path name of the file backing the MTD device
*
****************************************************************************/
-FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path,
- size_t offset, size_t mtdlen,
- int16_t sectsize,
- int32_t erasesize)
+FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset,
+ int16_t sectsize, int32_t erasesize)
{
FAR struct file_dev_s *priv;
+ struct stat sb;
size_t nblocks;
+ size_t filelen;
int mode;
int ret;
+ /* Stat the file */
+
+ ret = nx_stat(path, &sb, 1);
+ if (ret < 0)
+ {
+ ferr("ERROR: Failed to stat %s: %d\n", path, ret);
+ return NULL;
+ }
+
+ filelen = sb.st_size;
+ if (offset > filelen)
+ {
+ ferr("ERROR: Offset beyond end of file\n");
+ return NULL;
+ }
+
+ filelen = filelen - offset;
+
/* Create an instance of the FILE MTD device state structure */
priv = (FAR struct file_dev_s *)kmm_zalloc(sizeof(struct file_dev_s));
@@ -778,7 +796,7 @@ FAR struct mtd_dev_s *blockmtd_initialize(FAR const char
*path,
/* Force the size to be an even number of the erase block size */
- nblocks = mtdlen / priv->erasesize;
+ nblocks = filelen / priv->erasesize;
if (nblocks < 3)
{
ferr("ERROR: Need to provide at least three full erase block\n");
@@ -807,17 +825,17 @@ FAR struct mtd_dev_s *blockmtd_initialize(FAR const char
*path,
}
/****************************************************************************
- * Name: blockmtd_teardown
+ * Name: filemtd_teardown
*
* Description:
- * Teardown a previously created blockmtd device.
+ * Teardown a previously created filemtd device.
*
* Input Parameters:
* dev - Pointer to the mtd driver instance.
*
****************************************************************************/
-void blockmtd_teardown(FAR struct mtd_dev_s *dev)
+void filemtd_teardown(FAR struct mtd_dev_s *dev)
{
FAR struct file_dev_s *priv = (FAR struct file_dev_s *)dev;
@@ -836,66 +854,11 @@ void blockmtd_teardown(FAR struct mtd_dev_s *dev)
kmm_free(priv);
}
-/****************************************************************************
- * Name: filemtd_initialize
- *
- * Description:
- * Create and initialize a FILE MTD device instance.
- *
- * Input Parameters:
- * path - Path name of the file backing the MTD device
- *
- ****************************************************************************/
-
-FAR struct mtd_dev_s *filemtd_initialize(FAR const char *path, size_t offset,
- int16_t sectsize, int32_t erasesize)
-{
- size_t filelen;
- struct stat sb;
- int ret;
-
- /* Stat the file */
-
- ret = nx_stat(path, &sb, 1);
- if (ret < 0)
- {
- ferr("ERROR: Failed to stat %s: %d\n", path, ret);
- return NULL;
- }
-
- filelen = sb.st_size;
-
- if (offset > filelen)
- {
- ferr("ERROR: Offset beyond end of file\n");
- return NULL;
- }
-
- return blockmtd_initialize(path, offset, filelen - offset, sectsize,
- erasesize);
-}
-
-/****************************************************************************
- * Name: filemtd_teardown
- *
- * Description:
- * Teardown a previously created filemtd device.
- *
- * Input Parameters:
- * dev - Pointer to the mtd driver instance.
- *
- ****************************************************************************/
-
-void filemtd_teardown(FAR struct mtd_dev_s *dev)
-{
- blockmtd_teardown(dev);
-}
-
/****************************************************************************
* Name: filemtd_isfilemtd
*
* Description:
- * Tests if the provided mtd is a filemtd or blockmtd device.
+ * Tests if the provided mtd is a filemtd device.
*
* Input Parameters:
* mtd - Pointer to the mtd.
diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h
index 721b4ec2d9..b765bc40b5 100644
--- a/include/nuttx/mtd/mtd.h
+++ b/include/nuttx/mtd/mtd.h
@@ -605,35 +605,6 @@ FAR struct mtd_dev_s *n25qxxx_initialize(FAR struct
qspi_dev_s *qspi,
FAR struct mtd_dev_s *w25qxxxjv_initialize(FAR struct qspi_dev_s *qspi,
bool unprotect);
-/****************************************************************************
- * Name: blockmtd_initialize
- *
- * Description:
- * Create and initialize a BLOCK MTD device instance.
- *
- * Input Parameters:
- * path - Path name of the block device backing the MTD device
- *
- ****************************************************************************/
-
-FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path,
- size_t offset, size_t mtdlen,
- int16_t sectsize,
- int32_t erasesize);
-
-/****************************************************************************
- * Name: blockmtd_teardown
- *
- * Description:
- * Teardown a previously created blockmtd device.
- *
- * Input Parameters:
- * dev - Pointer to the mtd driver instance.
- *
- ****************************************************************************/
-
-void blockmtd_teardown(FAR struct mtd_dev_s *dev);
-
/****************************************************************************
* Name: filemtd_initialize
*