Questions tagged [fsync]

The fsync system call causes all modified data and attributes associated to a given file descriptor to be moved to a permanent storage device.

The fsync system call causes all modified data and attributes associated to a given file descriptor to be moved to a permanent storage device.

http://www.freebsd.org/cgi/man.cgi?query=fsync&sektion=2

101 questions
177
votes
4 answers

What exactly is file.flush() doing?

I found this in the Python documentation for File Objects: flush() does not necessarily write the file’s data to disk. Use flush() followed by os.fsync() to ensure this behavior. So my question is: what exactly is Python's flush doing? I thought…
geek
  • 2,677
  • 4
  • 23
  • 21
72
votes
6 answers

Difference between fflush and fsync

I thought fsync() does fflush() internally, so using fsync() on a stream is OK. But I am getting an unexpected result when executed under network I/O. My code snippet: FILE* fp = fopen(file, "wb"); /* multiple fputs() calls like: */ fputs(buf,…
Adil
  • 2,418
  • 7
  • 34
  • 38
36
votes
3 answers

Is rename() without fsync() safe?

Is it safe to call rename(tmppath, path) without calling fsync(tmppath_fd) first? I want the path to always point to a complete file. I care mainly about Ext4. Is the rename() promised to be safe in all future Linux kernel versions? A usage example…
Ivo Danihelka
  • 3,382
  • 3
  • 31
  • 27
26
votes
4 answers

How to do fsync on an ofstream?

I want to make sure that an ofstream has been written to the disk device. What's the portable way (portable on POSIX systems) of doing this? Does that solve the problem if I open the file separately in read-only append mode to get a file descriptor…
Vik
  • 495
  • 1
  • 5
  • 11
19
votes
4 answers

How to durably rename a file in POSIX?

What's the correct way to durably rename a file in a POSIX file system? Specifically wondering about fsyncs on the directories. (If this depends on the OS/FS, I'm asking about Linux and ext3/ext4). Note: there are other questions on StackOverflow…
Yang
  • 16,037
  • 15
  • 100
  • 142
18
votes
4 answers

fflush, fsync and sync vs memory layers

I know there are already similar questions and I gave them a look but I couldn't find an explicit univocal answer to my question. I was just investigating online about these functions and their relationship with memory layers. In particular I found…
Antonino
  • 3,178
  • 3
  • 24
  • 39
15
votes
0 answers

Directories created by boost::filesystem::create_directories() not immediately accessible?

I am using boost::filesystem::create_directories() to create new directories. When I try to access these directories shortly after creation, I get an error saying: no such directory. But if I sleep for a while after creating directories everything…
polapts
  • 5,493
  • 10
  • 37
  • 49
13
votes
2 answers

ext4/fsync situation unclear in Android (Java)

Tim Bray's article "Saving Data Safely" left me with open questions. Today, it's over a month old and I haven't seen any follow-up on it, so I decided to address the topic here. One point of the article is that FileDescriptor.sync() should be called…
Markus Junginger
  • 6,950
  • 31
  • 52
10
votes
1 answer

Do the 'sync' and 'syncfs' system calls map to FUSE's 'fsync' calls?

The FUSE API doesn't expose a file-system level sync call, just fsync and fsyncdir. Does it mean that when sync is called (or syncfs inside a FUSE mountpoint), the kernel invokes fsync on all open files on all FUSE mounted file-systems? Or is there…
Petr
  • 62,528
  • 13
  • 153
  • 317
10
votes
2 answers

What does it take to be durable on Linux?

I'm writing some software to deal with pretty critical data, and need to know what exactly I need to do to achieve durability. Everywhere I look is contradictory information, so I'd appreciate any insight. There are three ways I write to…
Max
  • 2,760
  • 1
  • 28
  • 47
9
votes
3 answers

Force no more than one write/sync to disk in X seconds

I'm worried that I see through the disk LED and iotop quite some write activity every couple of seconds, mostly coming from the chromium's processes, on a completely idle system. It doesn't make any sense at all to have such a high number of writes…
brauliobo
  • 5,843
  • 4
  • 29
  • 34
8
votes
0 answers

Is it safe to call the Win32 FlushFileBuffers() function again if it previously returned an error?

I watched the talk: "PostgreSQL vs. fsync. How is it possible that PostgreSQL used fsync incorrectly for 20 years, and what we'll do about it." via https://fosdem.org/2019/schedule/event/postgresql_fsync/ and also read…
David Sitsky
  • 123
  • 5
8
votes
3 answers

Alternative to Fsync for windows c++

Is there an alternative to fsync for windows? (C++ builder) Fsync required to include unistd.h and it's only for unix systems Thanks!
user687459
  • 143
  • 5
  • 17
8
votes
4 answers

How to create a 10MB file filled with "000000..." data in golang?

I am intended to use fdatasync in a system like log or diskqueue. The first thing is to create a 10MB file with "000000..." in file system like ext4. But I don't know how to do it properly.
hardPass
  • 19,033
  • 19
  • 40
  • 42
7
votes
2 answers

Why fsync() takes much more time on Linux kernel 3.1.* than kernel 3.0

I have a test program. It takes about 37 seconds on Linux kernel 3.1.*, but only takes about 1 seconds on kernel 3.0.18 (I just replace the kernel on the same machine as before). Please give me a clue on how to improve it on kernel 3.1.…
qxia
  • 99
  • 1
  • 6
1
2 3 4 5 6 7