[Yaffs] file size rounded to 512 bytes

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Evgeny Habinsky
Date:  
To: yaffs
CC: Charles Manning
Subject: [Yaffs] file size rounded to 512 bytes
Hi,

I have a problem of new file size changing to a multiple of 512 after
reset. The
problem appeared after I upgraded YAFFS about a month ago and seems to
be
similar to that described by Tinger Yin not long ago:
http://www.aleph1.co.uk/lurker/message/20080801.071438.04e18aa4.en.html

The following piece of code in yaffs_WriteDataToFile() seems to be the
cause:

nBytesRead =
in->variant.fileVariant.fileSize -
((chunk - 1) * dev->nDataBytesPerChunk);

if (nBytesRead > dev->nDataBytesPerChunk) {
nBytesRead = dev->nDataBytesPerChunk;
}

nToWriteBack =
(nBytesRead >
(start + n)) ? nBytesRead : (start + n);

When I write a file of 1000 bytes into a new file nBytesRead evaluates
to a
negative number since the .fileSize is zero. But when it comes to
comparison
nBytesRead > (start + n) bad thing happens because start type changed
from int
to __u32 in revision 1.55. Unsigned start causes the whole comparison to
be
evaluated as unsigned and nToWriteBack gets negative nBytesRead instead
of
(start + n).

Please, approve the fix:

Index: SW_Src/Target/PPCApp/HLD/YAFFS2/yaffs_guts.c
===================================================================
--- SW_Src/Target/PPCApp/HLD/YAFFS2/yaffs_guts.c (revision 1918)
+++ SW_Src/Target/PPCApp/HLD/YAFFS2/yaffs_guts.c (revision 1919)
@@ -4831,7 +4831,7 @@

    nToWriteBack =
        (nBytesRead >
-        (start + n)) ? nBytesRead : (start + n);
+        ((int)start + n)) ? nBytesRead : (start + n);


   } else {
    nToCopy = dev->nDataBytesPerChunk - start;



Regards
Evgeny Habinsky
Software Engineer



------------------------------------------------------------------------
--------

Surf Communication Solutions
Tavor Building POB 343, Yokneam 20692, Israel
Tel: 972 73 714 0758
Mobile: 972 54 309 8624
Fax: 972 4 959 4055
Email:
Web: www.surf-com.com