[fpc-pascal] XML files and the ext4 bug

David Emerson dle3ab at angelbase.com
Thu Mar 12 08:31:56 CET 2009

I can't comment on pascal's XML handling, but perhaps I can shed some 
light on the situation. I belive this new filesystem thing will bite 
you if you do something like this:

assign (my_file, '/some/file');

rewrite (my_file);
// ... write out the contents of the file ...
close (my_file);

reset (my_file); <-- right here is where you get screwed.

ext4 and other modern filesystems have not committed your previous 
rewrite to disk yet! So when you try to reset and read the file, you 
get an EMPTY file from the OS. If you then read in the (empty) data, 
make a few changes and write it out again, you're going to end up with 
a patchy file.

Also, if some kind of crash occurs before the file has been sync'd then 
the file would be completely gone.

When I write a config file out, I usually do so by writing out program 
variables by name, hardcoded in my program -- rather than by retrieving 
data from a config file and then writing out the same data that I just 

If you must do it by reading and then writing, then call (the pascal 
equivalent of) fsync after close, keeping in mind that you will have to 
wait for the (very slow) disk whenever that sync gets called.

Disclaimer: I don't REALLY know what I'm talking about: I am really 
going out on a limb with some guesswork here. But I think I understood 
Ts'o's message, and I doubt fpc calls sync on close ;)

Thanks, by the way, for including that message from Theodore Ts'o, which 
I found to be quite enlightening!


On Wed 11 Mar 2009, Gustavo Enrique Jimenez wrote:
> Hi
> Seems like the ext4 file system has a bug or some issue with files
> updated often :
> https://bugs.edge.launchpad.net/ubuntu/+source/linux/+bug/317781
> I use XML files heavily. It is great, XML units save me a lot of work
> ! My programs update de xml files quite often.
> I am concerned about this particular ext4 bug. Could you say if
> freepascal's XML units are affected by this bug ? ext4 developers
> recomend this :
> Thanks in advance
> Gustavo
> ps: excuse my english
> ____________________________

More information about the fpc-pascal mailing list