Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
March 31, 2005, 3:15 am

Hi,
I met a problem that, I'm trying to write a big
file into my flash. Actually I write the file
in many rounds, which means via many write() calls
with each time a partial piece.
After all the write() returned and the returned length
is valid, I reboot my device immediately. But after rebooting, I
found the file written in flash is not complete, its size
is smaller than that I wrote.
I was wondering whether the write() has returned but does not
mean the real buffer is written done. So the reboot would cause
the file imcomplete. Is this correct?
Actually I tried with system call "sync" before reboot, but fail.
Can anyone help me?
Thanks
sarick
I met a problem that, I'm trying to write a big
file into my flash. Actually I write the file
in many rounds, which means via many write() calls
with each time a partial piece.
After all the write() returned and the returned length
is valid, I reboot my device immediately. But after rebooting, I
found the file written in flash is not complete, its size
is smaller than that I wrote.
I was wondering whether the write() has returned but does not
mean the real buffer is written done. So the reboot would cause
the file imcomplete. Is this correct?
Actually I tried with system call "sync" before reboot, but fail.
Can anyone help me?
Thanks
sarick

Re: write() has returned, but data is not completely write into flash?
if u check the reboot scripts for many systems the sync() system call
is called multiple times before reboot since the sync system call is
just a hint to synchronize the the disc and does not initiate the
process immediately
is called multiple times before reboot since the sync system call is
just a hint to synchronize the the disc and does not initiate the
process immediately

Re: write() has returned, but data is not completely write into flash?

Do you mean that I should try issue multiple sync(), or sync() does
not help my case??
Actually I tried both sync() and fsync(), but fail.
Also I add an O_SYNC flag when opening the file descriptor with open(),
but still doesn't fix the problem.
Any suggestions?
Thanks
Sarick

Re: write() has returned, but data is not completely write into flash?

'man 2 sync' gives (among other things):
"
BUGS
According to the standard specification (e.g., SVID), sync() schedules
the writes, but may return before the actual writing is done. However,
since version 1.3.20 Linux does actually wait. (This still does not
guarantee data integrity: modern disks have large caches.)
"
It's probably not the best practice to assume sync() will sync everything
down. Try using multiple syncs with a 1sec or more delay before you actualy
reboot the machine.
Also, did you try it on another flash disk?
Does data loss happen always or sometimes it goes ok?
Regards,
Mario

Re: write() has returned, but data is not completely write into flash?

In addition to file system cacheing problems that can be solved via
"sync", the flash system itself (e.g. a Compact Flash card) might have a
reset feature (pin or command).
The rebooting might trigger this reset and thus the Flash system might
abort the write cycle. This might result in bad data, file system error
or even in destruction of the internal bad block lists of the Flash
system and same would become completely unusable.
-Michael
Site Timeline
- » HELP: PC104 IO card Driver Problem
- — Next thread in » Embedded Linux
-
- » how to login automatically?
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Static allocation and data hiding
- — The site's Newest Thread. Posted in » Embedded Programming
-