If you can follow Eric's suggestion, I'd go with that first.
Otherwise, if you have the source code for the application that is writing to
the file, add the fsync() system call following every write() and before
calling close().
If the above doesn't work (I expect it should, although read below for the fsck
requirement), you can also try writing to the block device in /dev. I don't
know how this might be buffered when it comes to MTD though, so some
experimentation may be required. What I'm thinking is that your code could
open the device (such as /dev/mtd/1) and write to it directly and not use a
filesystem at all. Issues would be: is data buffered before being written
(would require the fsync() call), maintaining data size (no filesystem = no
file size info), and determining when the partition is full (again, no
filesystem = no space available checks).
Background:
When a filesystem is mounted, the superblock on the media is marked
"is_mounted". Unmounting the filesystem clears that flag. When the system is
booted it checks that value when the mount is attempted. If the flag is false,
the mount proceeds normally. If the flag is set, then the filesystem was
mounted when power was lost and the fsck is required/reported depending on
various configuration settings.
--- In "eric.robishaw" <> wrote:
> > So, does anyone have more real-world experience here? Technically, I'm
> > only writing to a very small preferences/settings file and never leave the
> > file open for more than it takes to write out a few dozen words and then
> > the file is immediately closed. The chance that the file is open when
> > power is turned off is really small.
>
> Seems to me if you have only one file you're concerned about, it would be
> easier to use a backup-copy scheme than messing with file system
> implementations and all that. Always have 2 copies of the file. If you
> can't read the latest, revert to the previous one.
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|