[En-Nut-Discussion] Strange behavior with files using file attributes '+' or 'a'

Michael Bieri mibieri at ee.ethz.ch
Wed Feb 27 20:09:19 CET 2008


>
> Confirmed. Case '+' works for "r+" and "w+", but requires special 
> handling for "a+".
>
>   
Are you sure it does work for "r+" and "w+"? The _O_TRUNC flag is set 
whenever a '+' is used an will then clear the existing data in every 
case. (see PhatFileOpen in phatfs.c on line 444) UPDATE: Ok, you saw it 
out by yourself :-)

I worked around this using low-level IO, so I open a file with 
_open(..., _O_BINARY | _O_CREAT ). Now, the file is no longer cleared. 
But there's another issue: When you write some bytes somewhere in the 
file, the new bytes overwrite (as you expect) the old data. The problem 
now is, that the filesize grows for every byte you write. After 
overwriting some bytes somewhere in the file, the filesize grows with 
the same number of bytes, and so you have the same number of bytes of 
trash at the end of file.

This problem probably could be caused in PhatFileWrite(...) on line 650 
in phatfs.c. Is it correct, that the filesize is increased in every 
case? I think, it should only be increased if one writes at the end of a 
file.



More information about the En-Nut-Discussion mailing list