public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Robert Kaiser <rob@sysgo.de>
Cc: linux-mtd@lists.infradead.org, Jörn Engel <joern@wohnheim.fh-wedel.de>
Subject: Re: MTD concat layer
Date: Fri, 15 Feb 2002 15:58:20 +0000	[thread overview]
Message-ID: <3402.1013788700@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.21.0202121938210.25544-102000@dagobert.svc.sysgo.de>

rob@sysgo.de said:
>  attached is my first version of the MTD "concatenation layer". This
> basically allows to build virtual MTD devices by concatenating
> existing ones, so it is -in a way- the opposite of partitioning. I
> would like to add this to the MTD CVS and so I'm asking people to have
> a look at it. 

> +#if defined(CONFIG_MTD_CONCAT) || defined(CONFIG_MTD_CONCAT_MODULE) 

Don't ever do that. Modules should be, well, modular - don't make other 
stuff depend on whether you happened to build a particular module today or 
not.

It doesn't look like you have the concat_erase code right. An erase which 
covers more than one subdev will only get partially done.

I think the best way to do this would be to merge it with the existing
partition code. The question of how to actually _register_ these remains
open, but I think the core code ought to be something like this...

--- mtdpart.c	2001/11/27 14:55:11	1.25
+++ mtdpart.c	2002/02/15 15:02:51
@@ -21,13 +21,19 @@
 /* Our partition linked list */
 static LIST_HEAD(mtd_partitions);
 
+struct mtd_part_section {
+	struct mtd_info *master;
+	uint32_t logical_offset; /* In the 'partition' */
+	uint32_t phys_offset; /* In the master */
+	uint32_t len;
+};
+
 /* Our partition node structure */
 struct mtd_part {
 	struct mtd_info mtd;
-	struct mtd_info *master;
-	u_int32_t offset;
-	int index;
 	struct list_head list;
+	int nr_sects;
+	struct mtd_part_section sections[0];
 };
 
 /*
@@ -46,12 +52,41 @@ static int part_read (struct mtd_info *m
 			size_t *retlen, u_char *buf)
 {
 	struct mtd_part *part = PART(mtd);
+	size_t thisretlen;
+	size_t totretlen = 0;
+	int sect;
+	int ret = 0;
+
 	if (from >= mtd->size)
-		len = 0;
-	else if (from + len > mtd->size)
-		len = mtd->size - from;
-	return part->master->read (part->master, from + part->offset, 
-					len, retlen, buf);
+		return -EINVAL;
+
+	for (sect = 0; sect < part->nr_sects; sect_ofs += part->sections[sect].len, sect++) {
+		struct mtd_part_section *thissect = &part->sections[sect];
+		uint32_t thisofs, thislen;
+
+		if (from >= thissect->logical_offset + thissect->len)
+			continue;
+		
+		/* Offset within this section */
+		thisofs = from - thissect->logical_offset;
+		/* Trim length */
+		thislen = min(len, thissect->len - thisofs);
+		thisofs += thissect->phys_offset;
+
+		ret = part->master->read (part->master, from + part->offset, 
+					len, &thisretlen, buf);
+
+		if (ret)
+			goto out;
+
+		totretlen += thisretlen;
+		buf += thisretlen;
+		from += thisretlen;
+	}
+ out:
+	*retlen = totretlen;
+	return ret;
+
 }
 
 static int part_write (struct mtd_info *mtd, loff_t to, size_t len,
@@ -224,7 +259,6 @@ int add_mtd_partitions(struct mtd_info *
 		slave->mtd.erase = part_erase;
 		slave->master = master;
 		slave->offset = parts[i].offset;
-		slave->index = i;
 
 		if (slave->offset == MTDPART_OFS_APPEND)
 			slave->offset = cur_offset;


--
dwmw2

  parent reply	other threads:[~2002-02-15 15:47 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-12 18:40 MTD concat layer Robert Kaiser
2002-02-13  7:56 ` Suspend Erase bug in cfi_cmdset0001.c Joakim Tjernlund
2002-02-14  8:17   ` Joakim Tjernlund
2002-02-13 11:00 ` MTD concat layer Joakim Tjernlund
2002-02-13 11:04   ` David Woodhouse
2002-02-13 11:34     ` Robert Kaiser
2002-02-13 11:37     ` Robert Schwebel
2002-02-13 13:33       ` Daniel Engström
2002-02-13 14:01         ` Eric W. Biederman
2002-02-15 15:58 ` David Woodhouse [this message]
2002-02-15 17:43   ` Robert Kaiser
2002-02-15 18:02     ` David Woodhouse
2002-02-15 18:40       ` Jörn Engel
2002-02-16 10:33         ` Robert Kaiser
2002-02-16 10:43       ` Robert Kaiser
2002-02-16 10:43         ` David Woodhouse
2002-02-16 11:03           ` Robert Kaiser
2002-02-16 11:08             ` David Woodhouse
2002-02-16 14:56             ` Brian J. Fox
2002-02-17 10:36               ` Robert Kaiser
2002-02-17 19:05                 ` Brian J. Fox
2002-02-18  8:48                   ` Robert Kaiser
2002-02-18  9:05                     ` David Woodhouse
2002-02-18 15:53                       ` Brian J. Fox
2002-02-18 17:01                         ` Robert Kaiser
2002-02-18 17:02                           ` David Woodhouse
2002-02-18 15:46                     ` Brian J. Fox
2002-02-20 14:28 ` Jonas Holmberg
2002-02-20 15:35   ` Robert Kaiser
2002-02-21 14:51     ` Jonas Holmberg
2002-02-26 11:32       ` Robert Kaiser
2002-03-06 13:37         ` Jonas Holmberg
2002-03-06 16:02           ` Robert Kaiser
  -- strict thread matches above, loose matches on Subject: below --
2002-02-14 11:14 Jonas Holmberg
2002-03-08 16:08 Robert Kaiser
2002-03-08 16:22 ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3402.1013788700@redhat.com \
    --to=dwmw2@infradead.org \
    --cc=joern@wohnheim.fh-wedel.de \
    --cc=linux-mtd@lists.infradead.org \
    --cc=rob@sysgo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox