public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Vyacheslav Kovalevsky <slava.kovalevskiy.2014@gmail.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org
Subject: File name is not persisted if opened with O_SYNC and O_TRUNC flags
Date: Thu, 12 Feb 2026 14:51:47 +0300	[thread overview]
Message-ID: <4b207a36-5789-41d2-ac17-df86d4cde6da@gmail.com> (raw)

Detailed description
====================

Hello, there seems to be an issue with O_SYNC flag when used together 
with O_TRUNC on various file systems.
Opening a file with O_SYNC (or using fsync(fd)) should persist directory 
entry.
However, if O_SYNC is used together with O_TRUNC the file will be 
missing if system crashes.
According to POSIX this is OK, but most file systems provide stronger 
guarantees (would be actually nice to have a more recent documentation 
on this behavior).
This happens on Btrfs, ext4, XFS, F2FS and likely other file systems.


System info
===========

Linux version 6.19-rc7, also tested on 6.17


How to reproduce
================

```
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
   int status;

   status = creat("file", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
   printf("CREAT: %d\n", status);
   close(status);

   status = open("file", O_RDWR | O_TRUNC | O_SYNC);
   printf("OPEN: %d\n", status);
}
// after the crash `file` is missing
```

Steps:
1. Create and mount new file system in default configuration.
2. Change directory to root of the file system and run the compiled test.
3. Cause hard system crash (e.g. QEMU `system_reset` command).
4. Remount file system after crash.
5. Observe that file is missing.


             reply	other threads:[~2026-02-12 11:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-12 11:51 Vyacheslav Kovalevsky [this message]
2026-02-13  7:33 ` File name is not persisted if opened with O_SYNC and O_TRUNC flags Christoph Hellwig
2026-02-13 10:25   ` Vyacheslav Kovalevsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b207a36-5789-41d2-ac17-df86d4cde6da@gmail.com \
    --to=slava.kovalevskiy.2014@gmail.com \
    --cc=brauner@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox