OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / storage / fd.h
1 /*-------------------------------------------------------------------------
2  *
3  * fd.h
4  *        Virtual file descriptor definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2014, 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);
72 extern int      FileRead(File file, char *buffer, int amount);
73 extern int      FileWrite(File file, char *buffer, int amount);
74 extern int      FileSync(File file);
75 extern off_t FileSeek(File file, off_t offset, int whence);
76 extern int      FileTruncate(File file, off_t offset);
77 extern char *FilePathName(File file);
78
79 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
80 extern FILE *AllocateFile(const char *name, const char *mode);
81 extern int      FreeFile(FILE *file);
82
83 /* Operations that allow use of pipe streams (popen/pclose) */
84 extern FILE *OpenPipeStream(const char *command, const char *mode);
85 extern int      ClosePipeStream(FILE *file);
86
87 /* Operations to allow use of the <dirent.h> library routines */
88 extern DIR *AllocateDir(const char *dirname);
89 extern struct dirent *ReadDir(DIR *dir, const char *dirname);
90 extern int      FreeDir(DIR *dir);
91
92 /* Operations to allow use of a plain kernel FD, with automatic cleanup */
93 extern int      OpenTransientFile(FileName fileName, int fileFlags, int fileMode);
94 extern int      CloseTransientFile(int fd);
95
96 /* If you've really really gotta have a plain kernel FD, use this */
97 extern int      BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
98
99 /* Miscellaneous support routines */
100 extern void InitFileAccess(void);
101 extern void set_max_safe_fds(void);
102 extern void closeAllVfds(void);
103 extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
104 extern bool TempTablespacesAreSet(void);
105 extern Oid      GetNextTempTableSpace(void);
106 extern void AtEOXact_Files(void);
107 extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
108                                   SubTransactionId parentSubid);
109 extern void RemovePgTempFiles(void);
110
111 extern int      pg_fsync(int fd);
112 extern int      pg_fsync_no_writethrough(int fd);
113 extern int      pg_fsync_writethrough(int fd);
114 extern int      pg_fdatasync(int fd);
115 extern int      pg_flush_data(int fd, off_t offset, off_t amount);
116 extern void fsync_fname(char *fname, bool isdir);
117
118 /* Filename components for OpenTemporaryFile */
119 #define PG_TEMP_FILES_DIR "pgsql_tmp"
120 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
121
122 #endif   /* FD_H */