Add some functions to fd.c for the convenience of extensions.
authorRobert Haas <rhaas@postgresql.org>
Tue, 8 Mar 2016 15:09:50 +0000 (10:09 -0500)
committerRobert Haas <rhaas@postgresql.org>
Tue, 8 Mar 2016 15:09:50 +0000 (10:09 -0500)
For example, if you want to perform an ioctl() on a file descriptor
opened through the fd.c routines, there's no way to do that without
being able to get at the underlying fd.

KaiGai Kohei

src/backend/storage/file/fd.c
src/include/storage/fd.h

index 1b301001f09b9e6542f2ecb61b550750d04fb8e1..37a2ae6b643e43c9143213973231e648d0042589 100644 (file)
@@ -1577,6 +1577,40 @@ FilePathName(File file)
    return VfdCache[file].fileName;
 }
 
+/*
+ * Return the raw file descriptor of an opened file.
+ *
+ * The returned file descriptor will be valid until the file is closed, but
+ * there are a lot of things that can make that happen.  So the caller should
+ * be careful not to do much of anything else before it finishes using the
+ * returned file descriptor.
+ */
+int
+FileGetRawDesc(File file)
+{
+   Assert(FileIsValid(file));
+   return VfdCache[file].fd;
+}
+
+/*
+ * FileGetRawFlags - returns the file flags on open(2)
+ */
+int
+FileGetRawFlags(File file)
+{
+   Assert(FileIsValid(file));
+   return VfdCache[file].fileFlags;
+}
+
+/*
+ * FileGetRawMode - returns the mode bitmask passed to open(2)
+ */
+int
+FileGetRawMode(File file)
+{
+   Assert(FileIsValid(file));
+   return VfdCache[file].fileMode;
+}
 
 /*
  * Make room for another allocatedDescs[] array entry if needed and possible.
index 4a3fccbaa9b8372889c4948f97d0ea00a74f0718..6faa8ad8a616fcfff09e7957eb120b07764a5214 100644 (file)
@@ -75,6 +75,9 @@ 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);
+extern int  FileGetRawFlags(File file);
+extern int FileGetRawMode(File file);
 
 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
 extern FILE *AllocateFile(const char *name, const char *mode);