Skip to content

Commit 070140e

Browse files
committed
Add some functions to fd.c for the convenience of extensions.
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
1 parent 77a1d1e commit 070140e

File tree

2 files changed

+37
-0
lines changed
  • src
    • backend/storage/file
    • include/storage

2 files changed

+37
-0
lines changed

src/backend/storage/file/fd.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,40 @@ FilePathName(File file)
15771577
return VfdCache[file].fileName;
15781578
}
15791579

1580+
/*
1581+
* Return the raw file descriptor of an opened file.
1582+
*
1583+
* The returned file descriptor will be valid until the file is closed, but
1584+
* there are a lot of things that can make that happen. So the caller should
1585+
* be careful not to do much of anything else before it finishes using the
1586+
* returned file descriptor.
1587+
*/
1588+
int
1589+
FileGetRawDesc(File file)
1590+
{
1591+
Assert(FileIsValid(file));
1592+
return VfdCache[file].fd;
1593+
}
1594+
1595+
/*
1596+
* FileGetRawFlags - returns the file flags on open(2)
1597+
*/
1598+
int
1599+
FileGetRawFlags(File file)
1600+
{
1601+
Assert(FileIsValid(file));
1602+
return VfdCache[file].fileFlags;
1603+
}
1604+
1605+
/*
1606+
* FileGetRawMode - returns the mode bitmask passed to open(2)
1607+
*/
1608+
int
1609+
FileGetRawMode(File file)
1610+
{
1611+
Assert(FileIsValid(file));
1612+
return VfdCache[file].fileMode;
1613+
}
15801614

15811615
/*
15821616
* Make room for another allocatedDescs[] array entry if needed and possible.

src/include/storage/fd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ extern int FileSync(File file);
7575
extern off_t FileSeek(File file, off_t offset, int whence);
7676
extern int FileTruncate(File file, off_t offset);
7777
extern char *FilePathName(File file);
78+
extern int FileGetRawDesc(File file);
79+
extern int FileGetRawFlags(File file);
80+
extern int FileGetRawMode(File file);
7881

7982
/* Operations that allow use of regular stdio --- USE WITH CAUTION */
8083
extern FILE *AllocateFile(const char *name, const char *mode);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy