summaryrefslogtreecommitdiff
path: root/src/backend/storage/file/fd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r--src/backend/storage/file/fd.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 1db54650eef..81ba3edbbec 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.115 2004/12/31 22:00:51 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/file/fd.c,v 1.116 2005/05/20 14:53:26 momjian Exp $
*
* NOTES:
*
@@ -232,11 +232,27 @@ static void RemovePgTempFilesInDir(const char *tmpdirname);
/*
- * pg_fsync --- same as fsync except does nothing if enableFsync is off
+ * pg_fsync --- do fsync with or without writethrough
*/
int
pg_fsync(int fd)
{
+#ifndef HAVE_FSYNC_WRITETHROUGH_ONLY
+ if (sync_method != SYNC_METHOD_FSYNC_WRITETHROUGH)
+ return pg_fsync_no_writethrough(fd);
+ else
+#endif
+ return pg_fsync_writethrough(fd);
+}
+
+
+/*
+ * pg_fsync_no_writethrough --- same as fsync except does nothing if
+ * enableFsync is off
+ */
+int
+pg_fsync_no_writethrough(int fd)
+{
if (enableFsync)
return fsync(fd);
else
@@ -244,6 +260,24 @@ pg_fsync(int fd)
}
/*
+ * pg_fsync_writethrough
+ */
+int
+pg_fsync_writethrough(int fd)
+{
+ if (enableFsync)
+#ifdef WIN32
+ return _commit(fd);
+#elif defined(__darwin__)
+ return (fcntl(fd, F_FULLFSYNC, 0) == -1) ? -1 : 0;
+#else
+ return -1;
+#endif
+ else
+ return 0;
+}
+
+/*
* pg_fdatasync --- same as fdatasync except does nothing if enableFsync is off
*
* Not all platforms have fdatasync; treat as fsync if not available.