gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
5.9KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * fd.h
  4. * Virtual file descriptor definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, 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. * calls:
  16. *
  17. * File {Close, Read, Write, Size, Sync}
  18. * {Path Name Open, Allocate, Free} File
  19. *
  20. * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
  21. * Use them for all file activity...
  22. *
  23. * File fd;
  24. * fd = PathNameOpenFile("foo", O_RDONLY);
  25. *
  26. * AllocateFile();
  27. * FreeFile();
  28. *
  29. * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
  30. * use FreeFile, not fclose, to close it. AVOID using stdio for files
  31. * that you intend to hold open for any length of time, since there is
  32. * no way for them to share kernel file descriptors with other files.
  33. *
  34. * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
  35. * open directories (DIR*), and OpenTransientFile/CloseTransientFile for an
  36. * unbuffered file descriptor.
  37. */
  38. #ifndef FD_H
  39. #define FD_H
  40. #include <dirent.h>
  41. typedef int File;
  42. /* GUC parameter */
  43. extern PGDLLIMPORT int max_files_per_process;
  44. extern PGDLLIMPORT bool data_sync_retry;
  45. /*
  46. * This is private to fd.c, but exported for save/restore_backend_variables()
  47. */
  48. extern int max_safe_fds;
  49. /*
  50. * On Windows, we have to interpret EACCES as possibly meaning the same as
  51. * ENOENT, because if a file is unlinked-but-not-yet-gone on that platform,
  52. * that's what you get. Ugh. This code is designed so that we don't
  53. * actually believe these cases are okay without further evidence (namely,
  54. * a pending fsync request getting canceled ... see ProcessSyncRequests).
  55. */
  56. #ifndef WIN32
  57. #define FILE_POSSIBLY_DELETED(err) ((err) == ENOENT)
  58. #else
  59. #define FILE_POSSIBLY_DELETED(err) ((err) == ENOENT || (err) == EACCES)
  60. #endif
  61. /*
  62. * prototypes for functions in fd.c
  63. */
  64. /* Operations on virtual Files --- equivalent to Unix kernel file ops */
  65. extern File PathNameOpenFile(const char *fileName, int fileFlags);
  66. extern File PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
  67. extern File OpenTemporaryFile(bool interXact);
  68. extern void FileClose(File file);
  69. extern int FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info);
  70. extern int FileRead(File file, char *buffer, int amount, off_t offset, uint32 wait_event_info);
  71. extern int FileWrite(File file, char *buffer, int amount, off_t offset, uint32 wait_event_info);
  72. extern int FileSync(File file, uint32 wait_event_info);
  73. extern off_t FileSize(File file);
  74. extern int FileTruncate(File file, off_t offset, uint32 wait_event_info);
  75. extern void FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info);
  76. extern char *FilePathName(File file);
  77. extern int FileGetRawDesc(File file);
  78. extern int FileGetRawFlags(File file);
  79. extern mode_t FileGetRawMode(File file);
  80. /* Operations used for sharing named temporary files */
  81. extern File PathNameCreateTemporaryFile(const char *name, bool error_on_failure);
  82. extern File PathNameOpenTemporaryFile(const char *name);
  83. extern bool PathNameDeleteTemporaryFile(const char *name, bool error_on_failure);
  84. extern void PathNameCreateTemporaryDir(const char *base, const char *name);
  85. extern void PathNameDeleteTemporaryDir(const char *name);
  86. extern void TempTablespacePath(char *path, Oid tablespace);
  87. /* Operations that allow use of regular stdio --- USE WITH CAUTION */
  88. extern FILE *AllocateFile(const char *name, const char *mode);
  89. extern int FreeFile(FILE *file);
  90. /* Operations that allow use of pipe streams (popen/pclose) */
  91. extern FILE *OpenPipeStream(const char *command, const char *mode);
  92. extern int ClosePipeStream(FILE *file);
  93. /* Operations to allow use of the <dirent.h> library routines */
  94. extern DIR *AllocateDir(const char *dirname);
  95. extern struct dirent *ReadDir(DIR *dir, const char *dirname);
  96. extern struct dirent *ReadDirExtended(DIR *dir, const char *dirname,
  97. int elevel);
  98. extern int FreeDir(DIR *dir);
  99. /* Operations to allow use of a plain kernel FD, with automatic cleanup */
  100. extern int OpenTransientFile(const char *fileName, int fileFlags);
  101. extern int OpenTransientFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
  102. extern int CloseTransientFile(int fd);
  103. /* If you've really really gotta have a plain kernel FD, use this */
  104. extern int BasicOpenFile(const char *fileName, int fileFlags);
  105. extern int BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode);
  106. /* Make a directory with default permissions */
  107. extern int MakePGDirectory(const char *directoryName);
  108. /* Miscellaneous support routines */
  109. extern void InitFileAccess(void);
  110. extern void set_max_safe_fds(void);
  111. extern void closeAllVfds(void);
  112. extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
  113. extern bool TempTablespacesAreSet(void);
  114. extern int GetTempTablespaces(Oid *tableSpaces, int numSpaces);
  115. extern Oid GetNextTempTableSpace(void);
  116. extern void AtEOXact_Files(bool isCommit);
  117. extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
  118. SubTransactionId parentSubid);
  119. extern void RemovePgTempFiles(void);
  120. extern bool looks_like_temp_rel_name(const char *name);
  121. extern int pg_fsync(int fd);
  122. extern int pg_fsync_no_writethrough(int fd);
  123. extern int pg_fsync_writethrough(int fd);
  124. extern int pg_fdatasync(int fd);
  125. extern void pg_flush_data(int fd, off_t offset, off_t amount);
  126. extern void fsync_fname(const char *fname, bool isdir);
  127. extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
  128. extern int durable_unlink(const char *fname, int loglevel);
  129. extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
  130. extern void SyncDataDirectory(void);
  131. extern int data_sync_elevel(int elevel);
  132. /* Filename components */
  133. #define PG_TEMP_FILES_DIR "pgsql_tmp"
  134. #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
  135. #endif /* FD_H */
上海开阖软件有限公司 沪ICP备12045867号-1