On Tue, Dec 6, 2011 at 10:31 AM, 张磊 <leilei874@gmail.com> wrote:
but as the size of treenode is 32bytes and one treenode contains 8 or 16 physical chunk id. if one chunk equals one page that has 2kb data,so that one file can be as large as  2^16 * 2KB=128MB. that's what i mean.

what does chunk_group and tnode_size used for?
i'm confused about tnode_size and chunk_group in the sourcecode.

If you check yaffs_guts_initialise, you may find that the  tnode_width is not always 16. It depends on how many trunks are there in a device (value of x below). In case of a larger flash, a wider tree node (larger tnode_size) will be allocated which allows you to address more than 2^16 pages. 

If wide node is not enabled, the chunks are grouped. When you traverse the tnode tree, the 16bit chunk id you get is actually the group address. e.g. when you get chunk 0x5678, it is actually a group started at 0x567800, if chunk_grp_bits = 8. Again, you will be able to locate more than 2^16 pages.

Please feel free to correct me if anything misunderstood, Charles.

Line 4685, yaffs_guts.c

x = dev->param.chunks_per_block * (dev->internal_end_block + 1);

bits = calc_shifts_ceiling(x);

/* Set up tnode width if wide tnodes are enabled. */
if (!dev->param.wide_tnodes_disabled) {
/* bits must be even so that we end up with 32-bit words */
if (bits & 1)
bits++;
if (bits < 16)
dev->tnode_width = 16;
else
dev->tnode_width = bits;
} else {
dev->tnode_width = 16;
}

dev->tnode_mask = (1 << dev->tnode_width) - 1;

/* Level0 Tnodes are 16 bits or wider (if wide tnodes are enabled),
 * so if the bitwidth of the
 * chunk range we're using is greater than 16 we need
 * to figure out chunk shift and chunk_grp_size
 */

if (bits <= dev->tnode_width)
dev->chunk_grp_bits = 0;
else
dev->chunk_grp_bits = bits - dev->tnode_width;