Re: [Yaffs] yaffs_addr_to_chunk

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Charles Manning
Date:  
To: yaffs, spvoyek
Subject: Re: [Yaffs] yaffs_addr_to_chunk
On Tuesday 15 April 2014 10:45:01 wrote:
> Does anyone know why the variable passed into yaffs_addr_to_chunk()
> through the chunk_out parameter needs to be incremented by 1 afterwards?
>
> It looks like every place this function is called in yaffs_guts.c and
> yaffs_verify.c, the "chunk" is always incremented. Seems like
> yaffs_addr_to_chunk() should do that for us... as if it's giving the
> "wrong" answer/chunk.


Thanks for that observation. Yes, this could be neatened up.

As with many code bodies out there, this state exists due to some history.

addr_to_chunk() calculates the chunk and, offset into the zero-based chunk, of
an address (really an offset) into a file. Thus, offset 30 in a file would
give chunk 0, offset 30.

Since Yaffs uses 1-based chunkIds (chunk 0 == the file header), the value
needs to be incremented.

There were, historically, some other uses of addr_to_chunk() which have now
gone away.

This code could be cleaned up by:
* Giving addr_to_chunk() a better name (eg. file_offset_to_chunk)
* Doing the +1.

Something worth adding to my list of tasks, I think.

Thank you

-- Charles