summaryrefslogtreecommitdiff
path: root/nuttx/drivers/mtd
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-12-12 11:08:20 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-12-12 11:08:20 -0600
commitc59dbf885797fd6b4e6c1af4bdbe09148f9a300d (patch)
tree4d0d1e3fe5c85d13b3fd4886c0782d1cf58e1da0 /nuttx/drivers/mtd
parent6d1a08d951f3142833d30f9835a3889288e5d886 (diff)
downloadnuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.tar.gz
nuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.tar.bz2
nuttx-c59dbf885797fd6b4e6c1af4bdbe09148f9a300d.zip
Various fixes to the recent, big procfs checkin
Diffstat (limited to 'nuttx/drivers/mtd')
-rw-r--r--nuttx/drivers/mtd/mtd_partition.c182
-rw-r--r--nuttx/drivers/mtd/mtd_procfs.c44
2 files changed, 127 insertions, 99 deletions
diff --git a/nuttx/drivers/mtd/mtd_partition.c b/nuttx/drivers/mtd/mtd_partition.c
index 9fca44011..22041361c 100644
--- a/nuttx/drivers/mtd/mtd_partition.c
+++ b/nuttx/drivers/mtd/mtd_partition.c
@@ -540,10 +540,12 @@ static ssize_t part_procfs_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct part_procfs_file_s *attr;
- ssize_t ret, total = 0, blkpererase;
FAR struct mtd_geometry_s geo;
+ ssize_t total = 0;
+ ssize_t blkpererase;
+ ssize_t ret;
#ifdef CONFIG_MTD_PARTITION_NAMES
- char partname[11];
+ char partname[11];
FAR const char *ptr;
uint8_t x;
#endif
@@ -555,113 +557,127 @@ static ssize_t part_procfs_read(FAR struct file *filep, FAR char *buffer,
attr = (FAR struct part_procfs_file_s *)filep->f_priv;
DEBUGASSERT(attr);
- /* Provide the requested data */
+ /* If we are at the end of the list, then return 0 signifying the
+ * end-of-file. This also handles the special case when there are
+ * no registered MTD partitions.
+ */
- if (attr->nextpart == g_pfirstpartition)
+ if (attr->nextpart)
{
+ /* Output a header before the first entry */
+
+ if (attr->nextpart == g_pfirstpartition)
+ {
#ifdef CONFIG_MTD_PARTITION_NAMES
- total = snprintf(buffer, buflen, "Name Start Size");
+ total = snprintf(buffer, buflen, "Name Start Size");
#else
- total = snprintf(buffer, buflen, " Start Size");
+ total = snprintf(buffer, buflen, " Start Size");
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MTD
- total += snprintf(&buffer[total], buflen - total, " MTD\n");
+ total += snprintf(&buffer[total], buflen - total, " MTD\n");
#else
- total += snprintf(&buffer[total], buflen - total, "\n");
+ total += snprintf(&buffer[total], buflen - total, "\n");
#endif
- }
+ }
- while (attr->nextpart)
- {
- /* Get the geometry of the FLASH device */
+ /* Provide the requested data */
- ret = attr->nextpart->parent->ioctl(attr->nextpart->parent, MTDIOC_GEOMETRY,
- (unsigned long)((uintptr_t)&geo));
- if (ret < 0)
- {
- fdbg("ERROR: mtd->ioctl failed: %d\n", ret);
- return 0;
- }
+ do
+ {
+ /* Get the geometry of the FLASH device */
+
+ ret = attr->nextpart->parent->ioctl(attr->nextpart->parent,
+ MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
+ if (ret < 0)
+ {
+ fdbg("ERROR: mtd->ioctl failed: %d\n", ret);
+ return 0;
+ }
- /* Get the number of blocks per erase. There must be an even number of
- * blocks in one erase blocks.
- */
+ /* Get the number of blocks per erase. There must be an even number
+ * of blocks in one erase blocks.
+ */
- blkpererase = geo.erasesize / geo.blocksize;
+ blkpererase = geo.erasesize / geo.blocksize;
- /* Copy data from the next known partition */
+ /* Copy data from the next known partition */
#ifdef CONFIG_MTD_PARTITION_NAMES
- if (attr->nextpart->name == NULL)
- {
- strcpy(partname, "(noname) ");
- }
- else
- {
- ptr = attr->nextpart->name;
- for (x = 0; x < sizeof(partname) - 1; x++)
- {
- /* Test for end of partition name */
-
- if (*ptr == ',' || *ptr == '\0')
- {
- /* Perform space fill for alignment */
-
- partname[x] = ' ';
- }
- else
- {
- /* Copy next byte of partition name */
-
- partname[x] = *ptr++;
- }
- }
+ if (attr->nextpart->name == NULL)
+ {
+ strcpy(partname, "(noname) ");
+ }
+ else
+ {
+ ptr = attr->nextpart->name;
+ for (x = 0; x < sizeof(partname) - 1; x++)
+ {
+ /* Test for end of partition name */
+
+ if (*ptr == ',' || *ptr == '\0')
+ {
+ /* Perform space fill for alignment */
+
+ partname[x] = ' ';
+ }
+ else
+ {
+ /* Copy next byte of partition name */
+
+ partname[x] = *ptr++;
+ }
+ }
- partname[x] = '\0';
- }
+ partname[x] = '\0';
+ }
- /* Terminate the partition name and add to output buffer */
+ /* Terminate the partition name and add to output buffer */
- ret = snprintf(&buffer[total], buflen - total, "%s%7d %7d",
- partname, attr->nextpart->firstblock / blkpererase,
- attr->nextpart->neraseblocks);
+ ret = snprintf(&buffer[total], buflen - total, "%s%7d %7d",
+ partname, attr->nextpart->firstblock / blkpererase,
+ attr->nextpart->neraseblocks);
#else
- ret = snprintf(&buffer[total], buflen - total, "%7d %7d",
- attr->nextpart->firstblock / blkpererase,
- attr->nextpart->neraseblocks);
+ ret = snprintf(&buffer[total], buflen - total, "%7d %7d",
+ attr->nextpart->firstblock / blkpererase,
+ attr->nextpart->neraseblocks);
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MTD
- if (ret + total < buflen)
- {
- ret += snprintf(&buffer[total + ret], buflen - (total + ret),
- " %s\n", attr->nextpart->parent->name);
- }
+ if (ret + total < buflen)
+ {
+ ret += snprintf(&buffer[total + ret], buflen - (total + ret),
+ " %s\n", attr->nextpart->parent->name);
+ }
#else
- if (ret + total < buflen)
- {
- ret += snprintf(&buffer[total + ret], buflen - (total + ret), "\n");
- }
+ if (ret + total < buflen)
+ {
+ ret += snprintf(&buffer[total + ret], buflen - (total + ret),
+ "\n");
+ }
#endif
- if (ret + total < buflen)
- {
- /* It fit in the buffer totally. Advance total and move to
- * next partition.
- */
- total += ret;
- attr->nextpart = attr->nextpart->pnext;
- }
- else
- {
- /* This one didn't fit completely. Truncate the partial
- * entry and break the loop.
- */
- buffer[total] = '\0';
- break;
- }
- }
+ if (ret + total < buflen)
+ {
+ /* It fit in the buffer totally. Advance total and move to
+ * next partition.
+ */
+
+ total += ret;
+ attr->nextpart = attr->nextpart->pnext;
+ }
+ else
+ {
+ /* This one didn't fit completely. Truncate the partial
+ * entry and break the loop.
+ */
+
+ buffer[total] = '\0';
+ break;
+ }
+ }
+ while (attr->nextpart);
+ }
/* Update the file offset */
diff --git a/nuttx/drivers/mtd/mtd_procfs.c b/nuttx/drivers/mtd/mtd_procfs.c
index 2a2ba32a2..e1596003e 100644
--- a/nuttx/drivers/mtd/mtd_procfs.c
+++ b/nuttx/drivers/mtd/mtd_procfs.c
@@ -199,7 +199,8 @@ static ssize_t mtd_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct mtd_file_s *priv;
- ssize_t total = 0, ret;
+ ssize_t total = 0;
+ ssize_t ret;
fvdbg("buffer=%p buflen=%d\n", buffer, (int)buflen);
@@ -208,28 +209,39 @@ static ssize_t mtd_read(FAR struct file *filep, FAR char *buffer,
priv = (FAR struct mtd_file_s *)filep->f_priv;
DEBUGASSERT(priv);
- /* Provide the requested data */
-
- if (priv->pnextmtd == g_pfirstmtd)
- {
- total = snprintf(buffer, buflen, "Num Device\n");
- }
+ /* If we are at the end of the list, then return 0 signifying the
+ * end-of-file. This also handles the special case when there are
+ * no registered MTD devices.
+ */
- while (priv->pnextmtd)
+ if (priv->pnextmtd)
{
- ret = snprintf(&buffer[total], buflen - total, "%-5d%s\n",
- priv->pnextmtd->mtdno, priv->pnextmtd->name);
+ /* Output a header before the first entry */
- if (ret + total < buflen)
+ if (priv->pnextmtd == g_pfirstmtd)
{
- total += ret;
- priv->pnextmtd = priv->pnextmtd->pnext;
+ total = snprintf(buffer, buflen, "Num Device\n");
}
- else
+
+ /* The provide the requested data */
+
+ do
{
- buffer[total] = '\0';
- break;
+ ret = snprintf(&buffer[total], buflen - total, "%-5d%s\n",
+ priv->pnextmtd->mtdno, priv->pnextmtd->name);
+
+ if (ret + total < buflen)
+ {
+ total += ret;
+ priv->pnextmtd = priv->pnextmtd->pnext;
+ }
+ else
+ {
+ buffer[total] = '\0';
+ break;
+ }
}
+ while (priv->pnextmtd);
}
/* Update the file offset */