Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4844

C/C++ • Re: Use of sync(2) / fsync(2) before a hard before hard shutdowns?

$
0
0
I'm not certain about this, but I think you may want to try adding the "auto_da_alloc" mount option to the filesystem in /etc/fstab. See ext4(5) for details. The description sounds quite like what you are describing to me.

I think I'd also err towards using the write a new file and rename pattern, which the manpage describes as:

Code:

fd = open("foo.new")/write(fd,...)/close(fd)/ rename("foo.new", "foo")
Obviously you'd need to do the equivalent in C++, but it has an important benefit compared to overwriting the existing file. On a journaled filesystem, a file rename within the filesystem should be essentially "atomic". I.e. the rename should either happen or not happen in the journal recovery after a crash, and no file data blocks are written as part of the rename (just the directory / metadata). It should have the lowest chance of leaving a corrupt file after a crash, in my opinion, and it sounds like the auto_da_alloc flag will ensure that the data blocks are committed before the rename.

Statistics: Posted by Murph9000 — Tue Sep 03, 2024 12:53 am



Viewing all articles
Browse latest Browse all 4844

Trending Articles