SHARE
Facebook X Pinterest WhatsApp

ext4, application expectations and power management

Written By
thumbnail
Web Webster
Web Webster
Mar 17, 2009

“Asking the filesystem to truncate a file and then writing to it
is an invitation to failure – there’s clearly no way for it to
intuit the correct answer here. In the end this has been avoided by
avoiding delayed allocation when writing to a file that’s just been
truncated, so everything’s fine.

“However, there’s another case that also breaks. A common way of
saving files is to open(“foo.tmp”), write(), close() and then
rename(“foo.tmp”, “foo”). The mindset here is that a crash will
either result in foo.tmp being zero length, foo still being the
original file or foo being your new data. The important aspect of
this is that the desired behaviour of this code is that foo will
contain either the original data or the new data. You may suffer
data loss, but you won’t suffer complete data loss – the
application state will be consistent.

“When used with its (default) data=ordered journal option, ext3
provided these semantics. ext4 doesn’t. Instead, if you want to
ensure that your data doesn’t get trampled, it’s necessary to
fsync() before closing in order to make sure it hits disk.
Otherwise the rename can occur before the data is written, and
you’re back to a zero length file. ext4 doesn’t make guarantees
about whether data will be flushed before metadata is written.”

Complete
Story

thumbnail
Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Recommended for you...

5 Best Free and Open Source Text Expander Tools
webmaster
Jun 13, 2025
Grafito: Systemd Journal Log Viewer with a Beautiful Web UI
Bobby Borisov
Jun 12, 2025
FreeBSD Wants to Know a Few Things
brideoflinux
May 11, 2025
NVK enabled for Maxwell, Pascal, and Volta GPUs
Kara Bembridge
May 1, 2025
Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.