Skip to contentSkip to conversation

PATCH: allow JFFS2 to write to really small disks

PATCH Øyvind Harboe 3 participants 14 messages Aug 31, 2005 – Sep 5, 2005 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

The attached patch allows JFFS2 to write to really small JFFS2 disks.

This is e.g. useful when using JFFS2 for in-system one time programming of embedded device parameters: serial number, MAC, etc.

Comments?

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com

Index: build.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/build.c,v
retrieving revision 1.76

build.c 31 Aug 2005 09:01:34 -0000 renamed from build.c 30 Jul 2005 15:29:27 -0000 +0 -0
diff -u -r1.76 build.c
@@ -279,6 +279,14 @@
 
	c->resv_blocks_write = c->resv_blocks_deletion + (size / c->sector_size);

+ /* If the flash disk is smaller than resv_blocks_write, then we
+ allow writing to the disk anyway. The flash disk is then most likely
+ being used as write once - read many medimum, e.g. in-system configuration of
+ static parameters(e.g. MAC address of device in stored in "ROM"). */
+ if (c->resv_blocks_write * c->sector_size > c->flash_size) {
+ c->resv_blocks_write = 0;
+ }
+

	/* When do we let the GC thread run in the background */
 
	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;
#1 lore raw
Quoted 20 lines · Øyvind Harboe

The attached patch allows JFFS2 to write to really small JFFS2 disks.

This is e.g. useful when using JFFS2 for in-system one time programming of embedded device parameters: serial number, MAC, etc.

Comments?

Index: build.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/build.c,v
retrieving revision 1.76
diff -u -r1.76 build.c

build.c 31 Aug 2005 09:01:34 -0000 renamed from build.c 30 Jul 2005 15:29:27 -0000 +1 -0
@@ -279,6 +279,14 @@
 
 	c->resv_blocks_write = c->resv_blocks_deletion + (size / c->sector_size);
 
+	/* If the flash disk is smaller than resv_blocks_write, then we 

build.c 31 Aug 2005 09:01:34 -0000 line 292

Quoted 10 lines
build.c 31 Aug 2005 09:01:34 -0000 renamed from build.c 30 Jul 2005 15:29:27 -0000 +7 -0
+	   allow writing to the disk anyway. The flash disk is then most likely
+	      being used as write once - read many medimum, e.g. in-system configuration of 
+	         static parameters(e.g. MAC address of device in stored in "ROM"). */
+		 if (c->resv_blocks_write * c->sector_size > c->flash_size) {
+		   c->resv_blocks_write = 0; 
+		   }
+
 	/* When do we let the GC thread run in the background */
 
 	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;

Minor stuff: You indentation is broken.

If you changed the patch to add a mount option for the WORM case and check for the mount option instead, this might go in. Looks like it could be useful.

Jörn

Signature · 3 lines
Courage is not the absence of fear, but rather the judgement that
something else is more important than fear.
-- Ambrose Redmoon
#2 lore raw
Quoted 5 lines
Quoted 3 lines
	/* When do we let the GC thread run in the background */
 
	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;

Minor stuff: You indentation is broken.

Will fix of course. What emacs mode should I use for indentation? :-)

Quoted 3 lines

If you changed the patch to add a mount option for the WORM case and check for the mount option instead, this might go in. Looks like it could be useful.

I prefer it the way it is now. There are less options to read up on and document.

W.r.t. documentation it would possibly call for a footnote that the JFFS2 disk will only support read/write many times if it is large enough. If it is too small, it only supports Write Once Read Many.

What do you think?

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com
#3 lore raw
Quoted 8 lines · Øyvind Harboe
Quoted 6 lines
Quoted 4 lines
	/* When do we let the GC thread run in the background */
 
	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;

Minor stuff: You indentation is broken.

Will fix of course. What emacs mode should I use for indentation? :-)

No idea, I use vim. Try to mimic existing code, use scripts/Lindent or read Documentation/CodingStyle.

Quoted 4 lines
Quoted 3 lines

If you changed the patch to add a mount option for the WORM case and check for the mount option instead, this might go in. Looks like it could be useful.

Quoted 8 lines

I prefer it the way it is now. There are less options to read up on and document.

W.r.t. documentation it would possibly call for a footnote that the JFFS2 disk will only support read/write many times if it is large enough. If it is too small, it only supports Write Once Read Many.

What do you think?

I think that most users don't want JFFS2 to run in WORM mode. And for those users, failing on every write is actually better. They notice the problem right away, not just after a while.

People that want WORM mode are the minority and therefore should be the ones that are inconvenienced.

Jörn

Signature · 2 lines
The only real mistake is the one from which we learn nothing.
-- John Powell
#4 lore raw
Quoted 5 lines
Quoted 1 line

What do you think?

I think that most users don't want JFFS2 to run in WORM mode. And for those users, failing on every write is actually better. They notice the problem right away, not just after a while.

But who mounts a *tiny* JFFS2 volume except those that will be using it as a WORM drive?

This group of users could well be even tinier than those that want WORM drives.

My conclusion:

Make it a WORM drive if it is too small to support read/write many times.

Quoted 2 lines

People that want WORM mode are the minority and therefore should be the ones that are inconvenienced.

I agree with this principle, but my assumptions are different than yours, hence I'm currently leaning towards a different conclusion.

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com
#5 lore raw
Quoted 9 lines · Øyvind Harboe
Quoted 6 lines
Quoted 2 lines

What do you think?

I think that most users don't want JFFS2 to run in WORM mode. And for those users, failing on every write is actually better. They notice the problem right away, not just after a while.

But who mounts a *tiny* JFFS2 volume except those that will be using it as a WORM drive?

People making mistakes. It is a very important usability issue to mark mistakes as such. Making it appear as if everything is ok and having it fail later, possibly days or weeks later, is bad usability.

I would agree with you if the user-perceived behaviour was *immediatly* and *noticably* different. But unless people write enough data to fill their fs, the difference may go unnoticed.

Jörn

Signature · 3 lines
The wise man seeks everything in himself; the ignorant man tries to get
everything from somebody else.
-- unknown
#6 lore raw
Quoted 10 lines · Jörn Engel
Quoted 2 lines

But who mounts a *tiny* JFFS2 volume except those that will be using it as a WORM drive?

People making mistakes. It is a very important usability issue to mark mistakes as such. Making it appear as if everything is ok and having it fail later, possibly days or weeks later, is bad usability.

I would agree with you if the user-perceived behaviour was *immediatly* and *noticably* different. But unless people write enough data to fill their fs, the difference may go unnoticed.

Sounds good.

If I get some indication that there is a consensus from maintainers/committers to add this mount option, I'll go ahead and write it up.

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com
#7 lore raw
Quoted 13 lines · Øyvind Harboe
Quoted 10 lines · Jörn Engel
Quoted 2 lines

But who mounts a *tiny* JFFS2 volume except those that will be using it as a WORM drive?

People making mistakes. It is a very important usability issue to mark mistakes as such. Making it appear as if everything is ok and having it fail later, possibly days or weeks later, is bad usability.

I would agree with you if the user-perceived behaviour was *immediatly* and *noticably* different. But unless people write enough data to fill their fs, the difference may go unnoticed.

Quoted 5 lines

Sounds good.

If I get some indication that there is a consensus from maintainers/committers to add this mount option, I'll go ahead and write it up.

You're asking for too much. :)

Most of the time, most people just don't care. If they actually do care and are opposed to your patch, they will speak up. But you won't ever find out before actively trying to merge the patch.

Jörn

Signature · 2 lines
...one more straw can't possibly matter...
-- Kirby Bakken
#8 lore raw
Quoted 20 lines · Jörn Engel
Quoted 13 lines · Øyvind Harboe
Quoted 10 lines · Jörn Engel
Quoted 2 lines

But who mounts a *tiny* JFFS2 volume except those that will be using it as a WORM drive?

People making mistakes. It is a very important usability issue to mark mistakes as such. Making it appear as if everything is ok and having it fail later, possibly days or weeks later, is bad usability.

I would agree with you if the user-perceived behaviour was *immediatly* and *noticably* different. But unless people write enough data to fill their fs, the difference may go unnoticed.

Quoted 5 lines

Sounds good.

If I get some indication that there is a consensus from maintainers/committers to add this mount option, I'll go ahead and write it up.

Quoted 5 lines

You're asking for too much. :)

Most of the time, most people just don't care. If they actually do care and are opposed to your patch, they will speak up. But you won't ever find out before actively trying to merge the patch.

I agree with Jörn on this point. It should be a mount option.

Not that my opinion amounts to much... :)

josh

#9 lore raw
In reply to Jörn Engel
Quoted 9 lines
Quoted 3 lines

If I get some indication that there is a consensus from maintainers/committers to add this mount option, I'll go ahead and write it up.

You're asking for too much. :)

Most of the time, most people just don't care. If they actually do care and are opposed to your patch, they will speak up. But you won't ever find out before actively trying to merge the patch.

I guess. I'll set aside some time to read up on the mount options for JFFS2(incidentally I'm using JFFS2 for eCos) and put together a properly indented & commented patch.

Thanks for the feedback btw, hopefully this will work out.

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com
#10 lore raw
In reply to Jörn Engel

How about this patch?

It adds a mount option to allow Write Once Read Many if the disk is too small to support read/write many times.

W.r.t. eCos, I expect the WORM capability to be enabled via a CDL option.

Signature · 2 lines
Øyvind Harboe
http://www.zylin.com

Index: fs/jffs2/build.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/build.c,v
retrieving revision 1.77

jffs2/build.c +12 -0
diff -u -r1.77 build.c
@@ -279,6 +279,18 @@
 
 	c->resv_blocks_write = c->resv_blocks_deletion + (size / c->sector_size);
 
+	/* It is possible to mount a JFFS2 in a mode where it allows
+	   Write Once Read Many operation if the flash disk is too small
+	   to support read/write many times.
+	   
+	   If the flash disk is smaller than resv_blocks_write, then we 
+	   allow writing to the disk anyway. The flash disk is then most likely
+       being used as write once - read many medimum, e.g. in-system configuration of 
+	   static parameters(e.g. MAC address of device in stored in "ROM"). */
+	if ((c->flags & JFFS2_SB_FLAG_ALLOW_WORM)!=0)&& (c->resv_blocks_write * c->sector_size > c->flash_size)) {
+		c->resv_blocks_write = 0; 
+	}
+
 	/* When do we let the GC thread run in the background */
 
 	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;

Index: include/linux/jffs2_fs_sb.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/jffs2_fs_sb.h,v retrieving revision 1.52

linux/jffs2_fs_sb.h +3 -0
diff -u -r1.52 jffs2_fs_sb.h
@@ -16,6 +16,9 @@
 #define JFFS2_SB_FLAG_RO 1
 #define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */
 #define JFFS2_SB_FLAG_BUILDING 4 /* File system building is in progress */
+#define JFFS2_SB_FLAG_ALLOW_WORM 8 /* allow write once read many if the
+                                      disk is too small to support read/write
+                                      many times*/
 
 struct jffs2_inodirty;
 
#11 lore raw
Quoted 2 lines · Øyvind Harboe

To: [email protected]

Please keep everyone in the thread on Cc:. Being subscribed to a dozen mailing lists causes me to miss some things otherwise.

Quoted 7 lines

How about this patch?

It adds a mount option to allow Write Once Read Many if the disk is too small to support read/write many times.

W.r.t. eCos, I expect the WORM capability to be enabled via a CDL option.

I have to admit being clueless about eCos. For Linux, the parser bits are still missing. How about this patch? The parser stuff is quite large, as this appears to be the first JFFS2 mount option ever.

Jörn

Signature · 107 lines
The cheapest, fastest and most reliable components of a computer
system are those that aren't there.
-- Gordon Bell, DEC labratories


Signed-off-by: Jörn Engel <[email protected]>
---

 fs/jffs2/build.c            |    6 ++++++
 fs/jffs2/fs.c               |   41 +++++++++++++++++++++++++++++++++++++++++
 include/linux/jffs2_fs_sb.h |    7 ++++---
 3 files changed, 51 insertions(+), 3 deletions(-)

--- linux-2.6.13-rc6mtd/fs/jffs2/build.c~jffs2_worm	2005-08-26 17:18:04.000000000 +0200
+++ linux-2.6.13-rc6mtd/fs/jffs2/build.c	2005-09-04 10:29:39.000000000 +0200
@@ -279,6 +279,12 @@ static void jffs2_calc_trigger_levels(st
 
 	c->resv_blocks_write = c->resv_blocks_deletion + (size / c->sector_size);
 
+	/* Allow JFFS2 to run in WORM (write once read many) mode.
+	   This mode makes sense for small flashes with very rare
+	   updates of small amounts of data. */
+	if ((c->flags & JFFS2_SB_FLAG_WORM) && (c->nr_blocks < c->resv_blocks_write))
+		c->resv_blocks_write = 0; 
+
 	/* When do we let the GC thread run in the background */
 
 	c->resv_blocks_gctrigger = c->resv_blocks_write + 1;
--- linux-2.6.13-rc6mtd/fs/jffs2/fs.c~jffs2_worm	2005-09-04 10:15:36.000000000 +0200
+++ linux-2.6.13-rc6mtd/fs/jffs2/fs.c	2005-09-04 10:57:33.000000000 +0200
@@ -22,6 +22,7 @@
 #include <linux/vmalloc.h>
 #include <linux/vfs.h>
 #include <linux/crc32.h>
+#include <linux/parser.h>
 #include "nodelist.h"
 
 static int jffs2_flash_setup(struct jffs2_sb_info *c);
@@ -440,6 +441,44 @@ struct inode *jffs2_new_inode (struct in
 }
 
 
+enum {
+	opt_worm,
+};
+
+
+static match_table_t tokens = {
+	{opt_worm,	"worm"},
+};
+
+
+static int jffs2_parse_options(struct jffs2_sb_info *c, void *_data)
+{
+	char *data = _data;
+	char *p;
+	substring_t args[MAX_OPT_ARGS];
+
+	if (!data)
+		return 0;
+
+	while ((p = strsep(&data, ","))) {
+		int token;
+
+		if (!*p)
+			continue;
+		token = match_token(p, tokens, args);
+		switch (token) {
+		case opt_worm:
+			c->flags |= JFFS2_SB_FLAG_WORM;
+			break;
+		default:
+			printk(KERN_ERR"jffs2: unknown mount flag \"%s\"\n", p);
+			return -EINVAL;
+		}
+	}
+	return 0;
+}
+
+
 int jffs2_do_fill_super(struct super_block *sb, void *data, int silent)
 {
 	struct jffs2_sb_info *c;
@@ -459,6 +498,8 @@ int jffs2_do_fill_super(struct super_blo
 		return -EINVAL;
 	}
 #endif
+	if (jffs2_parse_options(c, data))
+		return -EINVAL;
 
 	c->flash_size = c->mtd->size;
 
--- linux-2.6.13-rc6mtd/include/linux/jffs2_fs_sb.h~jffs2_worm	2005-08-17 13:37:29.000000000 +0200
+++ linux-2.6.13-rc6mtd/include/linux/jffs2_fs_sb.h	2005-09-04 10:55:07.000000000 +0200
@@ -13,9 +13,10 @@
 #include <linux/list.h>
 #include <linux/rwsem.h>
 
-#define JFFS2_SB_FLAG_RO 1
-#define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */
-#define JFFS2_SB_FLAG_BUILDING 4 /* File system building is in progress */
+#define JFFS2_SB_FLAG_RO	1
+#define JFFS2_SB_FLAG_SCANNING	2 /* Flash scanning is in progress */
+#define JFFS2_SB_FLAG_BUILDING	4 /* File system building is in progress */
+#define JFFS2_SB_FLAG_WORM	8 /* Write once read many - writes but no GC */
 
 struct jffs2_inodirty;
#12 lore raw
Quoted 6 lines
Quoted 2 lines

W.r.t. eCos, I expect the WORM capability to be enabled via a CDL option.

I have to admit being clueless about eCos. For Linux, the parser bits are still missing. How about this patch? The parser stuff is quite large, as this appears to be the first JFFS2 mount option ever.

Do you think this is useful for Linux?

I mostly foresaw it as being useful for deeply embedded systems, like eCos.

Øyvind

#13 lore raw
Quoted 11 lines · On Mon, 5 September 2005 12:05:11 +0200, [email protected] wrote:
Quoted 7 lines
Quoted 3 lines

W.r.t. eCos, I expect the WORM capability to be enabled via a CDL option.

I have to admit being clueless about eCos. For Linux, the parser bits are still missing. How about this patch? The parser stuff is quite large, as this appears to be the first JFFS2 mount option ever.

Do you think this is useful for Linux?

I mostly foresaw it as being useful for deeply embedded systems, like eCos.

I don't know. So far you've been the only person to ask for this. If that doesn't change, maybe it would be best if you maintained a minimal patch and we would just forget about this. But if the patch is useful for others as well, we could merge it.

Anyone?

Jörn

Signature · 3 lines
A quarrel is quickly settled when deserted by one party; there is
no battle unless there be two.
-- Seneca