file I/O: writ to disk in parallel?

June 20th, 2012 - 11:35 pm ET by lmike | Report spam
Say an application code calls fwrite/write etc. to write a very long string "aaa ... 123 ... ccc" to a disk file, is it ever possible that the app/box crashes in the middle of the write operation, then it leaves a garbage like "aaa ... @#$@#$ ... ccc" or "@#$%@#$ ... 123 ... ccc" in the disk file?

Or, in other words, could the disk write head(s) (1) write parts of that string in parallel to the disk, OR (2) write the bytes not in order, e.g. first write "ccc", then "aaa" ... ? Any hard disks support that?
Thanks!
email Follow the discussionReplies 2 repliesReplies Make a reply

Replies

#1 Lusotec
June 21st, 2012 - 08:33 am ET | Report spam
Hash: SHA256

lmike wrote:
Say an application code calls fwrite/write etc. to write a very long
string "aaa ... 123 ... ccc" to a disk file, is it ever possible that the
app/box crashes in the middle of the write operation, then it leaves a
garbage like "aaa ... @#$@#$ ... ccc" or "@#$%@#$ ... 123 ... ccc" in the
disk file?

Or, in other words, could the disk write head(s) (1) write parts of that
string in parallel to the disk, OR (2) write the bytes not in order, e.g.
first write "ccc", then "aaa" ... ? Any hard disks support that? Thanks!



fwrite/write gives no guarantees on write order or if it is actually written
to the device. This is true even if there are no crashes or power issues. If
you needs *some* guarantees then look in to fsync.

Regards.

Similar topics