On Wednesday 24 November 2010 10:43:42 Bob Lee wrote: > YAFFS team, > > After investigating some corrupt files in our Android app, I think I've > narrowed the problem down to YAFFS. The same code on a FAT fs performs as > expected. > > First, it looks like RandomAccessFile.setLength(), which translates to > ftruncate(), can fail silently. For example, I can set the file length to > much more space than is available, and I don't get an error. AFAIK, FAT and yaffs are different in how they handle truncate and friends. AFAIK, FAT does not generate sparse files. If you truncate up or seek past the file extents and then write, FAT will fill the file with 0x00 bytes. YAFFS generates sparse files. If you don't actually write data then none is stored. The file has a "hole" which reads back as zero bytes. Thus, yaffs is likely truncating without writing data and is thus not failing. > I'm not sure > why else ftruncate() fails, but we've seen cases where the actual file > length (as reported by "ls -l") is less than it should > be. OK that sounds like a bug and I shall investigate. truncating a file up should return the file size, regardless of the data in the file. > RandomAccessFile.length(), which seeks to the end of the file, returns > the requested value, which is much longer than the available space. I even > tried writing and reading the last byte, and I still didn't get an error. Yup, they'll be zeros. > > Finally, File.length(), which uses stat, returns 0 for the length, That sounds wrong. It should be the file size. > and the > available space reported by "df" doesn't go down. :-( No space consumed so the free space does not reduce. > > As a workaround, I'm going to append bytes to the end of the file instead > of using ftruncate(), but I thought I should bring these issues to your > attention. That should work though you should not have to do it just to set the file size. Some people truncate up to pre-allocate space for a file. That will obviously not work if you have holes in the file. You could instead pre-allocate by writing zeros to the file until you get the desired length. Thanks for reporting the issue Bob. Were you sanebob before you started writing software? -- Charles