aboutsummaryrefslogtreecommitdiff
path: root/src/port/fdatasync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/fdatasync.c')
-rw-r--r--src/port/fdatasync.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/port/fdatasync.c b/src/port/fdatasync.c
new file mode 100644
index 00000000000..afef853aa3c
--- /dev/null
+++ b/src/port/fdatasync.c
@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ *
+ * fdatasync.c
+ * Win32 fdatasync() replacement
+ *
+ *
+ * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
+ *
+ * src/port/fdatasync.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#define UMDF_USING_NTSTATUS
+
+#ifdef FRONTEND
+#include "postgres_fe.h"
+#else
+#include "postgres.h"
+#endif
+
+#include "port/win32ntdll.h"
+
+int
+fdatasync(int fd)
+{
+ IO_STATUS_BLOCK iosb;
+ NTSTATUS status;
+ HANDLE handle;
+
+ handle = (HANDLE) _get_osfhandle(fd);
+ if (handle == INVALID_HANDLE_VALUE)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (initialize_ntdll() < 0)
+ return -1;
+
+ memset(&iosb, 0, sizeof(iosb));
+ status = pg_NtFlushBuffersFileEx(handle,
+ FLUSH_FLAGS_FILE_DATA_SYNC_ONLY,
+ NULL,
+ 0,
+ &iosb);
+
+ if (NT_SUCCESS(status))
+ return 0;
+
+ _dosmaperr(pg_RtlNtStatusToDosError(status));
+ return -1;
+}