[Yaffs] [Yaffs-archive] YAFFS: another "hole" bug fixed.

Charles Manning manningc2@actrix.gen.nz
Wed, 12 Nov 2003 09:51:58 +1300


--------------Boundary-00=_MMG7YCA1EECW1E7A7RKH
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

Along the same lines of the problem James discovered, I found a problem 
relating to holes in resized files.

This impacts all YAFFS versions (Linux, WinCE, direct...)

If one truncates a file then expands it again, then the expanded "holes" 
should be zeros.

However, all yaffs was doing for the partial page left at the end of the 
resize was just marking the number of valid bytes. Then, when the page got 
read back the old contets would be restored. It's a pretty wierd sequence...

YAFFS was not being fooled by the most common usage of truncation (truncation 
to zero length) or any other page-aligned truncations.

A simple one-liner in yaffs_ResizeFile fixes this, now in CVS.

See enclosed test case, but herewith  also a brief description:

After first write, file contents is "abcdefghijklmnopqrstuvwxyz".
After truncation file contents is "abc"
After second write file contents should be "abc\0\01", but with the bug was 
"abcde1".

-- CHarles


--------------Boundary-00=_MMG7YCA1EECW1E7A7RKH
Content-Type: text/x-c;
  charset="iso-8859-1";
  name="truncate_check.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="truncate_check.c"

I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvc3RhdC5oPgojaW5jbHVkZSA8ZmNudGwu
aD4KCnZvaWQgbWFpbih2b2lkKQp7CglpbnQgYTsKCWludCByOwoJaW50IGk7CglpbnQgbDsKCQoJ
Y2hhciB5WzEwXTsKCQoJdW5saW5rKCJ0cnVuY3Rlc3QiKTsKCQoJYSA9IG9wZW4oInRydW5jdGVz
dCIsIE9fQ1JFQVQgfCBPX1RSVU5DIHwgT19SRFdSLCAgU19JUkVBRCB8IFNfSVdSSVRFKTsKCQoJ
d3JpdGUoYSwiYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd6eXoiLDI2KTsKCQoJZnRydW5jYXRlKGEs
Myk7CglsPSBsc2VlayhhLDAsU0VFS19FTkQpOwoJCglwcmludGYoInRydW5jYXRlZCBsZW5ndGgg
aXMgJWRcbiIsbCk7CgkKCWxzZWVrKGEsNSxTRUVLX1NFVCk7Cgl3cml0ZShhLCIxIiwxKTsKCQoJ
bHNlZWsoYSwwLFNFRUtfU0VUKTsKCQoJciA9IHJlYWQoYSx5LDEwKTsKCQoJcHJpbnRmKCJyZWFk
ICVkIGJ5dGVzOiIscik7CgkKCWZvcihpID0gMDsgaSA8IHI7IGkrKykgcHJpbnRmKCJbJTAyWF0i
LHlbaV0pOwoJCglwcmludGYoIlxuIik7CgkKCQp9

--------------Boundary-00=_MMG7YCA1EECW1E7A7RKH--

---------------------------------------------------------------------------------------
This mailing list is hosted by Toby Churchill open software (www.toby-churchill.org).
If mailing list membership is no longer wanted you can remove yourself from the list by 
sending an email to yaffs-request@toby-churchill.org with the text "unsubscribe" 
(without the quotes) as the subject.