It seems to me that if you do multiple writes to a file then the cluster allocation or something gets corrupted. If you check the FS afterwards on windows, it will report problems and extend the file by 1 cluster, while linux fsck.vfat will truncate the file by some amount...
while doing an open(O_APPEND) + write + close multiple times seems to work fine.
any idea where the problem could be?
example fsck message:
dosfsck 3.0.1, 23 Nov 2008, FAT32, LFN
Checking we can access the last sector of the filesystem
Boot sector contents:
System ID "mkdosfs"
Media byte 0xf8 (hard disk)
512 bytes per logical sector
2048 bytes per cluster
1 reserved sector
First FAT starts at byte 512 (sector 1)
2 FATs, 16 bit entries
10240 bytes per FAT (= 20 sectors)
Root directory starts at byte 20992 (sector 41)
512 root directory entries
Data area starts at byte 37376 (sector 73)
5101 data clusters (10446848 bytes)
32 sectors/track, 64 heads
0 hidden sectors
20480 sectors total
FATs differ but appear to be intact. Use which FAT ?
1) Use first FAT
2) Use second FAT
? 1
/bla
File size is 655360 bytes, cluster chain length is 636928 bytes.
Truncating file to 636928 bytes.
multiple writes causes corruption
Re: multiple writes causes corruption
and i think i found another work-around for this.
instead of doing loop{open/write/close}, this works too:
open()
loop{
lseek(0, SEEK_SET) // begin of file
lseek(0, SEEK_END) // end of file
write()
}
close()
oh and to make it more clear this is what is problematic:
open(); loop { write() }; close();
instead of doing loop{open/write/close}, this works too:
open()
loop{
lseek(0, SEEK_SET) // begin of file
lseek(0, SEEK_END) // end of file
write()
}
close()
oh and to make it more clear this is what is problematic:
open(); loop { write() }; close();
Who is online
Users browsing this forum: No registered users and 1 guest