All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
To: zhao forrest <zhao_fusheng@hotmail.com>
Cc: dedekind@yandex.ru, linux-mtd@lists.infradead.org
Subject: Re: [PATCH]erase block header(revision 4)
Date: Mon, 3 Oct 2005 16:42:16 +0200	[thread overview]
Message-ID: <20051003144216.GF4639@wohnheim.fh-wedel.de> (raw)
In-Reply-To: <BAY17-F15F41E3E64959C3F1054D0E8800@phx.gbl>

On Mon, 3 October 2005 21:40:07 +0800, zhao forrest wrote:
>
> >> diff -auNrp mtd_9_28/fs/jffs2/fs.c mtd_9_28_EBH/fs/jffs2/fs.c
> >> --- mtd_9_28/fs/jffs2/fs.c	2005-09-28 10:51:57.000000000 +0800
> >> +++ mtd_9_28_EBH/fs/jffs2/fs.c	2005-09-28 11:51:53.000000000 +0800
> >> @@ -476,6 +476,7 @@ int jffs2_do_fill_super(struct super_blo
> >>  	}
> >>
> >>  	c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
> >> +	c->ebh_size = PAD(sizeof(struct jffs2_raw_ebh));
> >
> >Remove the PAD.  Instead you should make sure that PAD(sizeof(struct
> >jffs2_raw_ebh)) and sizeof(struct jffs2_raw_ebh) are equal.
> >
> >If they aren't, you have some other problem anyway.
> 
> I don't see a problem here, could you explain what kind of
> problem I will have??

You have a structure without proper alignment.  That would be ok for a
single field in the struct - the last - but it is much easier to make
the rule a bit stricter and require that the struct must be a multiple
of 4 or 8 bytes.

And once you've done that, there simply is no need for the PAD
anymore.  Less complicated.

> >> @@ -196,8 +197,14 @@ struct jffs2_eraseblock
> >>  	struct jffs2_raw_node_ref *last_node;
> >>
> >>  	struct jffs2_raw_node_ref *gc_node;	/* Next node to be garbage 
> collected */
> >> +
> >> +	uint32_t erase_count;
> >>  };
> >>
> >> +#define SET_EBFLAGS_HAS_EBH(jeb) (jeb->flags |= 1)
> >> +#define CLR_EBFLAGS_HAS_EBH(jeb) (jeb->flags &= ~1)
> >> +#define EBFLAGS_HAS_EBH(jeb) ((jeb->flags & 1) == 1)
> >
> >SET_EBFLAGS_HAS_EBH and CLR_EBFLAGS_HAS_EBH don't make sense.
> >EBFLAGS_SET_EBH does.
> Sorry. I can't understand why EBFLAGS_SET_EBH make sense.
> This flag is used to indicate whether an erase block has the
> eraseblock header. From EBFLAGS_SET_EBH code reader can't
> associate it with "_has_ eraseblock header".
> I think the flag's name is has_ebh instead of ebh.

Ok, I see.  Terms like "HAS" or "IS" are commonly used for
truth-returning functions/macros.  Hence, they should be avoided
elsewhere.  For flags, most people seem to use

FOO_HAS_BAR
FOO_SET_BAR
FOO_CLEAR_BAR

or some variants thereof.

> >> diff -auNrp mtd_9_28/fs/jffs2/nodemgmt.c 
> mtd_9_28_EBH/fs/jffs2/nodemgmt.c
> >> --- mtd_9_28/fs/jffs2/nodemgmt.c	2005-09-28 10:51:57.000000000 +0800
> >> +++ mtd_9_28_EBH/fs/jffs2/nodemgmt.c	2005-09-28 
> >13:42:53.000000000 
> +0800
> >> @@ -342,7 +342,10 @@ static int jffs2_do_reserve_space(struct
> >>
> >>  		jeb = c->nextblock;
> >>
> >> -		if (jeb->free_size != c->sector_size - c->cleanmarker_size) {
> >> +		if ((!EBFLAGS_HAS_EBH(jeb) && jeb->free_size != 
> >c->sector_size - 
> c->cleanmarker_size) ||
> >> +		    (EBFLAGS_HAS_EBH(jeb) && c->ebh_size && jeb->free_size 
> >!= 
> c->sector_size - ref_totlen(c, jeb, jeb->first_node)) ||
> >> +		    (EBFLAGS_HAS_EBH(jeb) && !c->ebh_size && jeb->free_size 
> >!= 
> c->sector_size))
> >> +		{
> >
> >This is too complicated.  What are you trying to do?
> I don't think it too complicated. It's only the extension of original
> condition judgement. The aim is that if free_size is not the expected
> size, then goto restart......

It was too complicated for me to understand quickly.  When something
like this happens, there are usually two options:
1. You fucked up and this thing is actually wrong.  Go and fix it.
2. Condition is essentially correct.  Create small function with a
   name like "action_foo_required", which returns 1 if you need to do
   foo, else 0.  The condition is a simple function call then, which
   should be obviously correct.
   The function itself can be easily expanded into many smaller
   conditions:
	if (this)
		return 1;
	if (that)
		return 0;
	if (other)
		return 1;
	return 0;
   Now each of the smaller conditions is simple to verify and can be
   commented if it isn't simple to verify.

Jörn

-- 
And spam is a useful source of entropy for /dev/random too!
-- Jasmine Strong

  parent reply	other threads:[~2005-10-03 14:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-03 13:40 [PATCH]erase block header(revision 4) zhao forrest
2005-10-03 13:50 ` Artem B. Bityutskiy
2005-10-03 14:28   ` Jörn Engel
2005-10-03 14:43     ` Artem B. Bityutskiy
2005-10-03 14:49       ` Jörn Engel
2005-10-09  6:08     ` zhao forrest
2005-10-09  7:06       ` Artem B. Bityutskiy
2005-10-09 10:35         ` Jörn Engel
2005-10-03 14:42 ` Jörn Engel [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-09-28  7:33 zhao forrest
2005-09-30  1:15 ` root
2005-09-30 11:29   ` Jörn Engel
2005-10-03 11:23 ` Jörn Engel

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=20051003144216.GF4639@wohnheim.fh-wedel.de \
    --to=joern@wohnheim.fh-wedel.de \
    --cc=dedekind@yandex.ru \
    --cc=linux-mtd@lists.infradead.org \
    --cc=zhao_fusheng@hotmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.