PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fd.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * fd.h
4  * Virtual file descriptor definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/fd.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 /*
16  * calls:
17  *
18  * File {Close, Read, Write, Seek, Tell, Sync}
19  * {Path Name Open, Allocate, Free} File
20  *
21  * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
22  * Use them for all file activity...
23  *
24  * File fd;
25  * fd = PathNameOpenFile("foo", O_RDONLY, 0600);
26  *
27  * AllocateFile();
28  * FreeFile();
29  *
30  * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
31  * use FreeFile, not fclose, to close it. AVOID using stdio for files
32  * that you intend to hold open for any length of time, since there is
33  * no way for them to share kernel file descriptors with other files.
34  *
35  * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
36  * open directories (DIR*), and OpenTransientFile/CloseTransient File for an
37  * unbuffered file descriptor.
38  */
39 #ifndef FD_H
40 #define FD_H
41 
42 #include <dirent.h>
43 
44 
45 /*
46  * FileSeek uses the standard UNIX lseek(2) flags.
47  */
48 
49 typedef char *FileName;
50 
51 typedef int File;
52 
53 
54 /* GUC parameter */
55 extern int max_files_per_process;
56 
57 /*
58  * This is private to fd.c, but exported for save/restore_backend_variables()
59  */
60 extern int max_safe_fds;
61 
62 
63 /*
64  * prototypes for functions in fd.c
65  */
66 
67 /* Operations on virtual Files --- equivalent to Unix kernel file ops */
68 extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
69 extern File OpenTemporaryFile(bool interXact);
70 extern void FileClose(File file);
71 extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info);
72 extern int FileRead(File file, char *buffer, int amount, uint32 wait_event_info);
73 extern int FileWrite(File file, char *buffer, int amount, uint32 wait_event_info);
74 extern int FileSync(File file, uint32 wait_event_info);
75 extern off_t FileSeek(File file, off_t offset, int whence);
76 extern int FileTruncate(File file, off_t offset, uint32 wait_event_info);
77 extern void FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info);
78 extern char *FilePathName(File file);
79 extern int FileGetRawDesc(File file);
80 extern int FileGetRawFlags(File file);
81 extern int FileGetRawMode(File file);
82 
83 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
84 extern FILE *AllocateFile(const char *name, const char *mode);
85 extern int FreeFile(FILE *file);
86 
87 /* Operations that allow use of pipe streams (popen/pclose) */
88 extern FILE *OpenPipeStream(const char *command, const char *mode);
89 extern int ClosePipeStream(FILE *file);
90 
91 /* Operations to allow use of the <dirent.h> library routines */
92 extern DIR *AllocateDir(const char *dirname);
93 extern struct dirent *ReadDir(DIR *dir, const char *dirname);
94 extern int FreeDir(DIR *dir);
95 
96 /* Operations to allow use of a plain kernel FD, with automatic cleanup */
97 extern int OpenTransientFile(FileName fileName, int fileFlags, int fileMode);
98 extern int CloseTransientFile(int fd);
99 
100 /* If you've really really gotta have a plain kernel FD, use this */
101 extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
102 
103 /* Miscellaneous support routines */
104 extern void InitFileAccess(void);
105 extern void set_max_safe_fds(void);
106 extern void closeAllVfds(void);
107 extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
108 extern bool TempTablespacesAreSet(void);
109 extern Oid GetNextTempTableSpace(void);
110 extern void AtEOXact_Files(void);
111 extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
112  SubTransactionId parentSubid);
113 extern void RemovePgTempFiles(void);
114 
115 extern int pg_fsync(int fd);
116 extern int pg_fsync_no_writethrough(int fd);
117 extern int pg_fsync_writethrough(int fd);
118 extern int pg_fdatasync(int fd);
119 extern void pg_flush_data(int fd, off_t offset, off_t amount);
120 extern void fsync_fname(const char *fname, bool isdir);
121 extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
122 extern int durable_unlink(const char *fname, int loglevel);
123 extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
124 extern void SyncDataDirectory(void);
125 
126 /* Filename components for OpenTemporaryFile */
127 #define PG_TEMP_FILES_DIR "pgsql_tmp"
128 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
129 
130 #endif /* FD_H */
int FreeDir(DIR *dir)
Definition: fd.c:2444
int durable_unlink(const char *fname, int loglevel)
Definition: fd.c:676
void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid, SubTransactionId parentSubid)
Definition: fd.c:2586
char * FileName
Definition: fd.h:49
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2335
void FileClose(File file)
Definition: fd.c:1493
int BasicOpenFile(FileName fileName, int fileFlags, int fileMode)
Definition: fd.c:936
int max_safe_fds
Definition: fd.c:139
void FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
Definition: fd.c:1618
int FileRead(File file, char *buffer, int amount, uint32 wait_event_info)
Definition: fd.c:1645
int CloseTransientFile(int fd)
Definition: fd.c:2305
File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
Definition: fd.c:1303
int pg_fsync_writethrough(int fd)
Definition: fd.c:362
int FreeFile(FILE *file)
Definition: fd.c:2277
uint32 SubTransactionId
Definition: c.h:401
unsigned int Oid
Definition: postgres_ext.h:31
Definition: dirent.h:9
static int fd(const char *x, int i)
Definition: preproc-init.c:105
int max_files_per_process
Definition: fd.c:126
File OpenTemporaryFile(bool interXact)
Definition: fd.c:1371
off_t FileSeek(File file, off_t offset, int whence)
Definition: fd.c:1851
Definition: dirent.c:25
FILE * OpenPipeStream(const char *command, const char *mode)
Definition: fd.c:2184
int durable_rename(const char *oldfile, const char *newfile, int loglevel)
Definition: fd.c:593
int ClosePipeStream(FILE *file)
Definition: fd.c:2470
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2401
bool TempTablespacesAreSet(void)
Definition: fd.c:2553
char * FilePathName(File file)
Definition: fd.c:1974
unsigned int uint32
Definition: c.h:268
Oid GetNextTempTableSpace(void)
Definition: fd.c:2565
void pg_flush_data(int fd, off_t offset, off_t amount)
Definition: fd.c:407
int OpenTransientFile(FileName fileName, int fileFlags, int fileMode)
Definition: fd.c:2144
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2094
void SyncDataDirectory(void)
Definition: fd.c:2933
int FileSync(File file, uint32 wait_event_info)
Definition: fd.c:1830
void closeAllVfds(void)
Definition: fd.c:2499
int FileGetRawFlags(File file)
Definition: fd.c:2000
int pg_fsync_no_writethrough(int fd)
Definition: fd.c:350
void AtEOXact_Files(void)
Definition: fd.c:2617
int FileGetRawDesc(File file)
Definition: fd.c:1990
int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel)
Definition: fd.c:712
void set_max_safe_fds(void)
Definition: fd.c:881
int pg_fdatasync(int fd)
Definition: fd.c:385
int FileTruncate(File file, off_t offset, uint32 wait_event_info)
Definition: fd.c:1939
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
void InitFileAccess(void)
Definition: fd.c:764
int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info)
Definition: fd.c:1590
int pg_fsync(int fd)
Definition: fd.c:333
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:567
void RemovePgTempFiles(void)
Definition: fd.c:2706
void SetTempTablespaces(Oid *tableSpaces, int numSpaces)
Definition: fd.c:2525
const char * name
Definition: encode.c:521
int FileGetRawMode(File file)
Definition: fd.c:2010
int FileWrite(File file, char *buffer, int amount, uint32 wait_event_info)
Definition: fd.c:1709
int File
Definition: fd.h:51