 src/backend/storage/file/fd.c |   18 ++++++++++++++++++
 src/include/storage/fd.h      |    1 +
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 1ba4946..4ef37df 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1577,6 +1577,24 @@ FilePathName(File file)
 	return VfdCache[file].fileName;
 }
 
+/*
+ * Return the raw file descriptor with an open file, and relevant flags.
+ *
+ * The returned file descriptor will be valid until the file is closed, and
+ * caller has to treat this descriptor not to make an adverse effect.
+ */
+int
+FileGetRawDesc(File file, int *f_flags, int *f_mode)
+{
+	Assert(FileIsValid(file));
+
+	if (f_flags)
+		*f_flags = VfdCache[file].fileFlags;
+	if (f_mode)
+		*f_mode = VfdCache[file].fileMode;
+
+	return VfdCache[file].fd;
+}
 
 /*
  * Make room for another allocatedDescs[] array entry if needed and possible.
diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h
index 7eabe09..1962160 100644
--- a/src/include/storage/fd.h
+++ b/src/include/storage/fd.h
@@ -75,6 +75,7 @@ extern int	FileSync(File file);
 extern off_t FileSeek(File file, off_t offset, int whence);
 extern int	FileTruncate(File file, off_t offset);
 extern char *FilePathName(File file);
+extern int	FileGetRawDesc(File file, int *f_flags, int *f_mode);
 
 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
 extern FILE *AllocateFile(const char *name, const char *mode);
