[PATCH v2 1/3] mtdpart: Allow adding a partition of a partition

Brian Norris computersforpeace at gmail.com
Wed Mar 4 11:23:10 PST 2015


On Tue, Feb 10, 2015 at 02:58:56PM -0800, Dan Ehrenberg wrote:
> MTD allows dynamic partitioning by the BLKPG ioctl.
> The current code restricts partition dynamic addition to work only on
> the master MTD device. This doesn't make a lot of sense, and is
> impossible to meet if the device is already partitioned (since the
> master MTD device is not visible). This commit removes the restriction.
> 
> Signed-off-by: Dan Ehrenberg <dehrenberg at chromium.org>

The big question I see is whether there is any downside to using
partitions as proxies for the 'master' MTD when adding/deleting
partitions. I think block devices prohibit this, but MTDs are different,
in that we don't always make the master available (i.e., we don't have
/dev/mtda, /dev/mtda1, /dev/mtda2, /dev/mtdb, /dev/mtdb1, ...).

> ---
>  drivers/mtd/mtdchar.c | 4 ----
>  drivers/mtd/mtdpart.c | 6 ++++++
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index 5356395..30215c7 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c
> @@ -545,10 +545,6 @@ static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
>  	switch (a.op) {
>  	case BLKPG_ADD_PARTITION:
>  
> -		/* Only master mtd device must be used to add partitions */
> -		if (mtd_is_partition(mtd))
> -			return -EINVAL;
> -
>  		/* Sanitize user input */
>  		p.devname[BLKPG_DEVNAMELTH - 1] = '\0';
>  
> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index a3e3a7d..7c6f526 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -566,6 +566,12 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
>  	if (length <= 0)
>  		return -EINVAL;
>  
> +	if (mtd_is_partition(master)) {
> +		struct mtd_part *master_partition = PART(master);
> +		offset += master_partition->offset;
> +		master = master_partition->master;

One of the problems here is the semantics. Do we really want to do this
offset computation when using the partition instead of the master? That
means if the original partitioning does not cover the early part of the
master MTD, then that piece is lost forever. e.g.,

 master, size 0x1000000, with a single partition
 /dev/mtd0, 1st partition 0x20000 - 0x40000

Then, ioctl(BLKPG, /dev/mtd0) can never create any partitions before
0x20000. But it CAN create partitions after 0x4000! We'd have to support
negative offsets for this to work consistently. (Now that I mention it,
does MTD's BLKPG even do sanity checking on the arguments? I think it
might actually accept negative offsets...)

Also, it's a bit odd that you can use one partition to delete either
another partition, or itself. e.g.,

	flash_part del /dev/mtd1 0  # deletes mtd0
	flash_part del /dev/mtd1 1  # deletes mtd1

This might be acceptable, if awkward. But the first problem looks like
it needs more thought.

> +	}
> +
>  	part.name = name;
>  	part.size = length;
>  	part.offset = offset;

Brian



More information about the linux-mtd mailing list