1 /*-------------------------------------------------------------------------
4 * Virtual file descriptor definitions.
7 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/fd.h
12 *-------------------------------------------------------------------------
18 * File {Close, Read, Write, Seek, Tell, Sync}
19 * {Path Name Open, Allocate, Free} File
21 * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
22 * Use them for all file activity...
25 * fd = PathNameOpenFile("foo", O_RDONLY);
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.
35 * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
36 * open directories (DIR*), and OpenTransientFile/CloseTransient File for an
37 * unbuffered file descriptor.
46 * FileSeek uses the standard UNIX lseek(2) flags.
53 extern int max_files_per_process;
56 * This is private to fd.c, but exported for save/restore_backend_variables()
58 extern int max_safe_fds;
62 * prototypes for functions in fd.c
65 /* Operations on virtual Files --- equivalent to Unix kernel file ops */
66 extern File PathNameOpenFile(const char *fileName, int fileFlags);
67 extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
68 extern File OpenTemporaryFile(bool interXact);
69 extern void FileClose(File file);
70 extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info);
71 extern int FileRead(File file, char *buffer, int amount, uint32 wait_event_info);
72 extern int FileWrite(File file, char *buffer, int amount, uint32 wait_event_info);
73 extern int FileSync(File file, uint32 wait_event_info);
74 extern off_t FileSeek(File file, off_t offset, int whence);
75 extern int FileTruncate(File file, off_t offset, uint32 wait_event_info);
76 extern void FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info);
77 extern char *FilePathName(File file);
78 extern int FileGetRawDesc(File file);
79 extern int FileGetRawFlags(File file);
80 extern mode_t FileGetRawMode(File file);
82 /* Operations used for sharing named temporary files */
83 extern File PathNameCreateTemporaryFile(const char *name, bool error_on_failure);
84 extern File PathNameOpenTemporaryFile(const char *name);
85 extern bool PathNameDeleteTemporaryFile(const char *name, bool error_on_failure);
86 extern void PathNameCreateTemporaryDir(const char *base, const char *name);
87 extern void PathNameDeleteTemporaryDir(const char *name);
88 extern void TempTablespacePath(char *path, Oid tablespace);
90 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
91 extern FILE *AllocateFile(const char *name, const char *mode);
92 extern int FreeFile(FILE *file);
94 /* Operations that allow use of pipe streams (popen/pclose) */
95 extern FILE *OpenPipeStream(const char *command, const char *mode);
96 extern int ClosePipeStream(FILE *file);
98 /* Operations to allow use of the <dirent.h> library routines */
99 extern DIR *AllocateDir(const char *dirname);
100 extern struct dirent *ReadDir(DIR *dir, const char *dirname);
101 extern struct dirent *ReadDirExtended(DIR *dir, const char *dirname,
103 extern int FreeDir(DIR *dir);
105 /* Operations to allow use of a plain kernel FD, with automatic cleanup */
106 extern int OpenTransientFile(const char *fileName, int fileFlags);
107 extern int OpenTransientFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
108 extern int CloseTransientFile(int fd);
110 /* If you've really really gotta have a plain kernel FD, use this */
111 extern int BasicOpenFile(const char *fileName, int fileFlags);
112 extern int BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
114 /* Miscellaneous support routines */
115 extern void InitFileAccess(void);
116 extern void set_max_safe_fds(void);
117 extern void closeAllVfds(void);
118 extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
119 extern bool TempTablespacesAreSet(void);
120 extern int GetTempTablespaces(Oid *tableSpaces, int numSpaces);
121 extern Oid GetNextTempTableSpace(void);
122 extern void AtEOXact_Files(void);
123 extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
124 SubTransactionId parentSubid);
125 extern void RemovePgTempFiles(void);
127 extern int pg_fsync(int fd);
128 extern int pg_fsync_no_writethrough(int fd);
129 extern int pg_fsync_writethrough(int fd);
130 extern int pg_fdatasync(int fd);
131 extern void pg_flush_data(int fd, off_t offset, off_t amount);
132 extern void fsync_fname(const char *fname, bool isdir);
133 extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
134 extern int durable_unlink(const char *fname, int loglevel);
135 extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
136 extern void SyncDataDirectory(void);
138 /* Filename components */
139 #define PG_TEMP_FILES_DIR "pgsql_tmp"
140 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"