From: Magnus Hagander <magnus@hagander.net>
Date: Fri, 13 Apr 2007 10:30:30 +0000 (+0000)
Subject: Add O_DIRECT support on Windows.
X-Git-Tag: REL8_3_BETA1~840
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15ebfeec2de8c29585ee4c976c089a7cd95331b2;p=postgresql

Add O_DIRECT support on Windows.

ITAGAKI Takahiro
---

diff --git a/src/include/port.h b/src/include/port.h
index 147a4de53d..1d33091f64 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.110 2007/02/07 00:28:55 petere Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.111 2007/04/13 10:30:30 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -277,6 +277,7 @@ extern bool rmtree(char *path, bool rmtopdir);
 /* open() and fopen() replacements to allow deletion of open files and
  * passing of other special options.
  */
+#define		O_DIRECT	0x80000000
 extern int	pgwin32_open(const char *, int,...);
 extern FILE *pgwin32_fopen(const char *, const char *);
 
diff --git a/src/port/open.c b/src/port/open.c
index f68b54cb6b..88fedc8475 100644
--- a/src/port/open.c
+++ b/src/port/open.c
@@ -6,7 +6,7 @@
  *
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/port/open.c,v 1.19 2007/02/13 02:06:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/open.c,v 1.20 2007/04/13 10:30:30 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,7 +53,6 @@ openFlagsToCreateFileFlags(int openFlags)
 
 /*
  *	 - file attribute setting, based on fileMode?
- *	 - handle other flags? (eg FILE_FLAG_NO_BUFFERING/FILE_FLAG_WRITE_THROUGH)
  */
 int
 pgwin32_open(const char *fileName, int fileFlags,...)
@@ -65,7 +64,7 @@ pgwin32_open(const char *fileName, int fileFlags,...)
 	/* Check that we can handle the request */
 	assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND |
 						 (O_RANDOM | O_SEQUENTIAL | O_TEMPORARY) |
-						 _O_SHORT_LIVED | O_DSYNC |
+						 _O_SHORT_LIVED | O_DSYNC | O_DIRECT |
 		  (O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags);
 
 	sa.nLength = sizeof(sa);
@@ -85,7 +84,8 @@ pgwin32_open(const char *fileName, int fileFlags,...)
 			   ((fileFlags & O_SEQUENTIAL) ? FILE_FLAG_SEQUENTIAL_SCAN : 0) |
 			  ((fileFlags & _O_SHORT_LIVED) ? FILE_ATTRIBUTE_TEMPORARY : 0) |
 				((fileFlags & O_TEMPORARY) ? FILE_FLAG_DELETE_ON_CLOSE : 0) |
-						((fileFlags & O_DSYNC) ? FILE_FLAG_WRITE_THROUGH : 0),
+					  ((fileFlags & O_DIRECT) ? FILE_FLAG_NO_BUFFERING : 0) |
+					  ((fileFlags & O_DSYNC) ? FILE_FLAG_WRITE_THROUGH : 0),
 						NULL)) == INVALID_HANDLE_VALUE)
 	{
 		switch (GetLastError())