Problem writing ini files on power off

G

Guest

I am using EWF to protect c: partition and writing to an .ini file on d:
which is not protected by ewf. D: is an extended partition. However, when cut
power to the box, the .ini file is either empty or corrupted on startup. The
..ini file is only 100k and is written to every 3 seconds but is closed after
a write. I've tried the following methods without any success:

1) fstream sync write
2) fstream sync write with hardware cache enable turned ON
3) fstream sync write with hardware cache enable turned OFF
4) fopen with commit flag and hardware cache enable turned OFF
5) Win32 Createfile with:
a. Write thru – ON
b. Buffering off
c. hardware cache enable turned OFF
d. (This method being the most direct!)


Is anyone doing the same type of thing? I need to allow power off but
persist some information to .ini file without becoming corrupt.

Thanks for any help.

Tim
 
G

Guest

It seems if I disable EWF, things work OK. Does this make sense? I'm
protecting partition c: with a EWF RAM configuration. Could this affect
writes to D: which is an unprotected extended partition?
 
K

KM

Tim,

Are you sure the problem doesn't happen with EWF Disabled? How much did you stress test it?
If this is still true, I'd stink it is just a timing issue. Without EWF it just happens a bit quickly to write the file.

In general, it is not (very NOT) recommended to cut the power while writing a file. Especially when you are dealing with a general
purpose FS (FAT, NTFS, etc.). This is why EWF is there.
So, the first question is what FS you use on your image on the unprotected partition?

I don't know any 100% stable solution for your problem but here is some tips:
- Use UPS (well.. this may be the 100% stable solution :) )
- Use NTFS instead of FAT on the unprotected partition. This may (or may not) make things a bit better as NTFS is more reliable
- Certainly turn off the write caching on the disk (note that you will lose some performance)
- Set FILE_FLAG_WRITE_THROUGH flag when you use CreateFile API call.
- Instead of MS FSs (not embedded anyway) use either some 3rd party (like the ones from Datalink) or just use a RAW partition to
preserve the data you need. That will be very fast access and you will not rely on any FS caching and buffering.
- Split the unprotected partition in two more - big and small. Use the small one for saving your data file there but protect it
with EWF anyway (not much RAM will be taken for that).
Commit the changes on the small partition once in a while (not 3 seconds, of course but hours). This way you can higher the
stability and integrity of the data in that file. You will certainly lose some log data if you cut the power at some moment.
 
B

Bill

A suggestion:
You may want to use two files ping-pong between them so only the last
one could be corrupted. That way you will always have something.

A Question:
How does the file system handle the write to disk? Does it get queued
and written later or right away? Is there a way to tell when it it
written? This won't help since you can't anticipate the power going
off.
 
K

KM

Bill,
A suggestion:
You may want to use two files ping-pong between them so only the last
one could be corrupted. That way you will always have something.

A Question:
How does the file system handle the write to disk? Does it get queued
and written later or right away? Is there a way to tell when it it
written? This won't help since you can't anticipate the power going
off.


Different file systems behave differenty.
With the FILE_FLAG_WRITE_THROUGH flag passed the writes should go to the disk level right away. However, there is usually FS cache,
Disk cache, etc. These you may want to avoid if you have raw access to the volume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top