FSYNC(3P)
πΎ FSYNC(3P) β the POSIX Programmer's Manual, bestie edition β¨
okay so this page lives in the POSIX Programmer's Manual, and it's all about fsync() π
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though, bestie: the Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the tea on Linux behavior), or the interface might not even be implemented on Linux at all. π
β¨ NAME β¨
fsync β synchronize changes to a file π¦
π SYNOPSIS π
#include <unistd.h>
int fsync(int fildes);
π DESCRIPTION π
So the fsync() function shall request that all data for the open file descriptor named by fildes gets transferred to the storage device associated with the file described by fildes. The nature of that transfer? implementation-defined, we don't make the rules. π«Ά
And the fsync() function shall not return until the system has completed that action, or until an error is detected. Like, it's not leaving you on read. It's staying until it's done. periodt.
If _POSIX_SYNCHRONIZED_IO is defined, then the fsync() function shall force all currently queued I/O operations associated with the file indicated by file descriptor fildes to the synchronized I/O completion state. All I/O operations shall be completed as defined for synchronized I/O file integrity completion. π
π₯ RETURN VALUE π₯
Upon successful completion, fsync() shall return 0. π
Otherwise, -1 shall be returned and errno set to indicate the error. And ngl, if the fsync() function fails, outstanding I/O operations are not guaranteed to have been completed. π¬
π ERRORS π
The fsync() function shall fail if:
EBADFβ Thefildesargument is not a valid descriptor. not a real one, bestie πEINTRβ Thefsync()function was interrupted by a signal. rude, honestly π€EINVALβ Thefildesargument does not refer to a file on which this operation is possible. it's giving "wrong file, no thanks" πEIOβ An I/O error occurred while reading from or writing to the file system. the vibe check failed π
In the event that any of the queued I/O operations fail, fsync() shall return the error conditions defined for read() and write().
The following sections are informative. (iykyk, they're the bonus lore π)
π EXAMPLES π
None. literally none. iconic behavior, honestly. π
π APPLICATION USAGE π
The fsync() function should be used by programs which require modifications to a file to be completed before continuing. For example: a program which contains a simple transaction facility might use it to ensure that all modifications to a file or files caused by a transaction are recorded. main character energy, keeping your data safe fr fr π«Ά
π§ RATIONALE π§
The fsync() function is intended to force a physical write of data from the buffer cache, and to assure that after a system crash or other failure, all data up to the time of the fsync() call is recorded on the disk. Since the concepts of buffer cache'', system crash'', physical write'', and non-volatile storage'' are not defined here, the wording has to be more abstract. it's giving "we have to be vague on purpose" π
If _POSIX_SYNCHRONIZED_IO is not defined, the wording relies heavily on the conformance document to tell the user what can be expected from the system. It is explicitly intended that a null implementation is permitted. This could be valid in the case where the system cannot assure non-volatile storage under any circumstances, or when the system is highly fault-tolerant and the functionality is not required. In the middle ground between these extremes, fsync() might or might not actually cause data to be written where it is safe from a power failure. The conformance document should identify at least that one configuration exists (and how to obtain that configuration) where this can be assured for at least some files that the user can select to use for critical data. It is not intended that an exhaustive list is required, but rather sufficient information is provided so that if critical data needs to be saved, the user can determine how the system is to be configured to allow the data to be written to non-volatile storage. so basically: read the docs, bestie πβ¨
It is reasonable to assert that the key aspects of fsync() are unreasonable to test in a test suite. That does not make the function any less valuable, just more difficult to test. A formal conformance test should probably force a system crash (power shutdown) during the test for this condition, but it needs to be done in such a way that automated testing does not require this to be done except when a formal record of the results is being made. It would also not be unreasonable to omit testing for fsync(), allowing it to be treated as a quality-of-implementation issue. no cap. π
π¦ FUTURE DIRECTIONS π¦
None. π
π SEE ALSO π
sync()- The Base Definitions volume of POSIX.1β2017,
<unistd.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! this came to you courtesy of IEEE/The Open Group, dated 2017, and the manual page is FSYNC(3P) β go sync something, ily, bye!! πβ¨ππ¦π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms