1 /*-------------------------------------------------------------------------
4 * Virtual file descriptor definitions.
7 * Portions Copyright (c) 1996-2011, 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 * {File Name Open, Allocate, Free} File
21 * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
22 * Use them for all file activity...
25 * fd = FilePathOpenFile("foo", O_RDONLY, 0600);
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*).
45 * FileSeek uses the standard UNIX lseek(2) flags.
48 typedef char *FileName;
54 extern int max_files_per_process;
58 * prototypes for functions in fd.c
61 /* Operations on virtual Files --- equivalent to Unix kernel file ops */
62 extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
63 extern File OpenTemporaryFile(bool interXact);
64 extern void FileSetTransient(File file);
65 extern void FileClose(File file);
66 extern int FilePrefetch(File file, off_t offset, int amount);
67 extern int FileRead(File file, char *buffer, int amount);
68 extern int FileWrite(File file, char *buffer, int amount);
69 extern int FileSync(File file);
70 extern off_t FileSeek(File file, off_t offset, int whence);
71 extern int FileTruncate(File file, off_t offset);
72 extern char *FilePathName(File file);
74 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
75 extern FILE *AllocateFile(const char *name, const char *mode);
76 extern int FreeFile(FILE *file);
78 /* Operations to allow use of the <dirent.h> library routines */
79 extern DIR *AllocateDir(const char *dirname);
80 extern struct dirent *ReadDir(DIR *dir, const char *dirname);
81 extern int FreeDir(DIR *dir);
83 /* If you've really really gotta have a plain kernel FD, use this */
84 extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
86 /* Miscellaneous support routines */
87 extern void InitFileAccess(void);
88 extern void set_max_safe_fds(void);
89 extern void closeAllVfds(void);
90 extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
91 extern bool TempTablespacesAreSet(void);
92 extern Oid GetNextTempTableSpace(void);
93 extern void AtEOXact_Files(void);
94 extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
95 SubTransactionId parentSubid);
96 extern void RemovePgTempFiles(void);
98 extern int pg_fsync(int fd);
99 extern int pg_fsync_no_writethrough(int fd);
100 extern int pg_fsync_writethrough(int fd);
101 extern int pg_fdatasync(int fd);
102 extern int pg_flush_data(int fd, off_t offset, off_t amount);
104 /* Filename components for OpenTemporaryFile */
105 #define PG_TEMP_FILES_DIR "pgsql_tmp"
106 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"