Header And Logo

PostgreSQL
| The world's most advanced open source database.

fd.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * fd.h
00004  *    Virtual file descriptor definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/storage/fd.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 
00015 /*
00016  * calls:
00017  *
00018  *  File {Close, Read, Write, Seek, Tell, Sync}
00019  *  {Path Name Open, Allocate, Free} File
00020  *
00021  * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
00022  * Use them for all file activity...
00023  *
00024  *  File fd;
00025  *  fd = PathNameOpenFile("foo", O_RDONLY, 0600);
00026  *
00027  *  AllocateFile();
00028  *  FreeFile();
00029  *
00030  * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
00031  * use FreeFile, not fclose, to close it.  AVOID using stdio for files
00032  * that you intend to hold open for any length of time, since there is
00033  * no way for them to share kernel file descriptors with other files.
00034  *
00035  * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
00036  * open directories (DIR*), and OpenTransientFile/CloseTransient File for an
00037  * unbuffered file descriptor.
00038  */
00039 #ifndef FD_H
00040 #define FD_H
00041 
00042 #include <dirent.h>
00043 
00044 
00045 /*
00046  * FileSeek uses the standard UNIX lseek(2) flags.
00047  */
00048 
00049 typedef char *FileName;
00050 
00051 typedef int File;
00052 
00053 
00054 /* GUC parameter */
00055 extern int  max_files_per_process;
00056 
00057 /*
00058  * This is private to fd.c, but exported for save/restore_backend_variables()
00059  */
00060 extern int  max_safe_fds;
00061 
00062 
00063 /*
00064  * prototypes for functions in fd.c
00065  */
00066 
00067 /* Operations on virtual Files --- equivalent to Unix kernel file ops */
00068 extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
00069 extern File OpenTemporaryFile(bool interXact);
00070 extern void FileClose(File file);
00071 extern int  FilePrefetch(File file, off_t offset, int amount);
00072 extern int  FileRead(File file, char *buffer, int amount);
00073 extern int  FileWrite(File file, char *buffer, int amount);
00074 extern int  FileSync(File file);
00075 extern off_t FileSeek(File file, off_t offset, int whence);
00076 extern int  FileTruncate(File file, off_t offset);
00077 extern char *FilePathName(File file);
00078 
00079 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
00080 extern FILE *AllocateFile(const char *name, const char *mode);
00081 extern int  FreeFile(FILE *file);
00082 
00083 /* Operations that allow use of pipe streams (popen/pclose) */
00084 extern FILE *OpenPipeStream(const char *command, const char *mode);
00085 extern int  ClosePipeStream(FILE *file);
00086 
00087 /* Operations to allow use of the <dirent.h> library routines */
00088 extern DIR *AllocateDir(const char *dirname);
00089 extern struct dirent *ReadDir(DIR *dir, const char *dirname);
00090 extern int  FreeDir(DIR *dir);
00091 
00092 /* Operations to allow use of a plain kernel FD, with automatic cleanup */
00093 extern int  OpenTransientFile(FileName fileName, int fileFlags, int fileMode);
00094 extern int  CloseTransientFile(int fd);
00095 
00096 /* If you've really really gotta have a plain kernel FD, use this */
00097 extern int  BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
00098 
00099 /* Miscellaneous support routines */
00100 extern void InitFileAccess(void);
00101 extern void set_max_safe_fds(void);
00102 extern void closeAllVfds(void);
00103 extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
00104 extern bool TempTablespacesAreSet(void);
00105 extern Oid  GetNextTempTableSpace(void);
00106 extern void AtEOXact_Files(void);
00107 extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
00108                   SubTransactionId parentSubid);
00109 extern void RemovePgTempFiles(void);
00110 
00111 extern int  pg_fsync(int fd);
00112 extern int  pg_fsync_no_writethrough(int fd);
00113 extern int  pg_fsync_writethrough(int fd);
00114 extern int  pg_fdatasync(int fd);
00115 extern int  pg_flush_data(int fd, off_t offset, off_t amount);
00116 
00117 /* Filename components for OpenTemporaryFile */
00118 #define PG_TEMP_FILES_DIR "pgsql_tmp"
00119 #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
00120 
00121 #endif   /* FD_H */