From 82b5ec73c0007df5cf0a5a04d54ea159e76b2951 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 30 Apr 2013 17:02:34 -0600 Subject: Incorporate comments from Ken Petit --- nuttx/drivers/mtd/mtd_partition.c | 36 ++++++++++++++++++++---------------- nuttx/include/nuttx/mtd.h | 4 ++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/nuttx/drivers/mtd/mtd_partition.c b/nuttx/drivers/mtd/mtd_partition.c index cc0b8c4df..aba6c6930 100644 --- a/nuttx/drivers/mtd/mtd_partition.c +++ b/nuttx/drivers/mtd/mtd_partition.c @@ -74,7 +74,7 @@ struct mtd_partition_s FAR struct mtd_dev_s *parent; /* The "parent" MTD driver that manages the * entire FLASH */ - off_t offset; /* Offset to the first sector of the managed + off_t firstblock; /* Offset to the first block of the managed * sub-region */ off_t neraseblocks; /* The number of erase blocks in the managed * sub-region */ @@ -130,11 +130,11 @@ static int part_erase(FAR struct mtd_dev_s *dev, off_t startblock, return -ENXIO; } - /* Just add the partition offset to the requested offset and let the + /* Just add the partition offset to the requested block and let the * underlying MTD driver perform the erase. */ - return priv->parent->erase(priv->parent, startblock + priv->offset, + return priv->parent->erase(priv->parent, startblock + priv->firstblock, nblocks); } @@ -163,11 +163,11 @@ static ssize_t part_bread(FAR struct mtd_dev_s *dev, off_t startblock, return -ENXIO; } - /* Just add the partition offset to the requested offset and let the + /* Just add the partition offset to the requested block and let the * underlying MTD driver perform the read. */ - return priv->parent->bread(priv->parent, startblock + priv->offset, + return priv->parent->bread(priv->parent, startblock + priv->firstblock, nblocks, buf); } @@ -196,11 +196,11 @@ static ssize_t part_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, return -ENXIO; } - /* Just add the partition offset to the requested offset and let the + /* Just add the partition offset to the requested block and let the * underlying MTD driver perform the write. */ - return priv->parent->bwrite(priv->parent, startblock + priv->offset, + return priv->parent->bwrite(priv->parent, startblock + priv->firstblock, nblocks, buf); } @@ -237,11 +237,11 @@ static ssize_t part_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, return -ENXIO; } - /* Just add the partition offset to the requested offset and let the + /* Just add the partition offset to the requested block and let the * underlying MTD driver perform the read. */ - newoffset = offset + priv->offset * priv->blocksize; + newoffset = offset + priv->firstblock * priv->blocksize; return priv->parent->read(priv->parent, newoffset, nbytes, buffer); } @@ -297,7 +297,7 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * return the sum to the caller. */ - *ppv = (FAR void *)(base + priv->offset * priv->blocksize); + *ppv = (FAR void *)(base + priv->firstblock * priv->blocksize); } } } @@ -307,13 +307,17 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) { /* Erase the entire partition */ - ret = priv->parent->erase(priv->parent, priv->offset, + ret = priv->parent->erase(priv->parent, priv->firstblock, priv->neraseblocks * priv->blkpererase); } break; default: - ret = -ENOTTY; /* Bad command */ + { + /* Pass any unhandled ioctl() calls to the underlying driver */ + + ret = priv->parent->ioctl(priv->parent, cmd, arg); + } break; } @@ -336,7 +340,7 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) * ****************************************************************************/ -FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t offset, +FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t firstblock, off_t nblocks) { FAR struct mtd_partition_s *part; @@ -371,8 +375,8 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t offset, * beyond the sub-region. */ - erasestart = (offset + blkpererase - 1) / blkpererase; - eraseend = (offset + nblocks) / blkpererase; + erasestart = (firstblock + blkpererase - 1) / blkpererase; + eraseend = (firstblock + nblocks) / blkpererase; if (erasestart >= eraseend) { @@ -407,7 +411,7 @@ FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t offset, part->child.ioctl = part_ioctl; part->parent = mtd; - part->offset = erasestart * blkpererase; + part->firstblock = erasestart * blkpererase; part->neraseblocks = eraseend - erasestart; part->blocksize = geo.blocksize; part->blkpererase = blkpererase; diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h index c0b9ee650..a196639c4 100644 --- a/nuttx/include/nuttx/mtd.h +++ b/nuttx/include/nuttx/mtd.h @@ -151,8 +151,8 @@ extern "C" * ****************************************************************************/ -FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, off_t offset, - off_t nblocks); +FAR struct mtd_dev_s *mtd_partition(FAR struct mtd_dev_s *mtd, + off_t firstblock, off_t nblocks); /**************************************************************************** * Name: ftl_initialize -- cgit v1.2.3