fd.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*-------------------------------------------------------------------------
  2. *
  3. * fd.h
  4. * Virtual file descriptor definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, 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, Seek, Tell, 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, 0600);
  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/CloseTransient File for an
  36. * unbuffered file descriptor.
  37. */
  38. #ifndef FD_H
  39. #define FD_H
  40. #include <dirent.h>
  41. /*
  42. * FileSeek uses the standard UNIX lseek(2) flags.
  43. */
  44. typedef char *FileName;
  45. typedef int File;
  46. /* GUC parameter */
  47. extern int max_files_per_process;
  48. /*
  49. * This is private to fd.c, but exported for save/restore_backend_variables()
  50. */
  51. extern int max_safe_fds;
  52. /*
  53. * prototypes for functions in fd.c
  54. */
  55. /* Operations on virtual Files --- equivalent to Unix kernel file ops */
  56. extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
  57. extern File OpenTemporaryFile(bool interXact);
  58. extern void FileClose(File file);
  59. extern int FilePrefetch(File file, off_t offset, int amount);
  60. extern int FileRead(File file, char *buffer, int amount);
  61. extern int FileWrite(File file, char *buffer, int amount);
  62. extern int FileSync(File file);
  63. extern off_t FileSeek(File file, off_t offset, int whence);
  64. extern int FileTruncate(File file, off_t offset);
  65. extern void FileWriteback(File file, off_t offset, off_t nbytes);
  66. extern char *FilePathName(File file);
  67. extern int FileGetRawDesc(File file);
  68. extern int FileGetRawFlags(File file);
  69. extern int FileGetRawMode(File file);
  70. /* Operations that allow use of regular stdio --- USE WITH CAUTION */
  71. extern FILE *AllocateFile(const char *name, const char *mode);
  72. extern int FreeFile(FILE *file);
  73. /* Operations that allow use of pipe streams (popen/pclose) */
  74. extern FILE *OpenPipeStream(const char *command, const char *mode);
  75. extern int ClosePipeStream(FILE *file);
  76. /* Operations to allow use of the <dirent.h> library routines */
  77. extern DIR *AllocateDir(const char *dirname);
  78. extern struct dirent *ReadDir(DIR *dir, const char *dirname);
  79. extern int FreeDir(DIR *dir);
  80. /* Operations to allow use of a plain kernel FD, with automatic cleanup */
  81. extern int OpenTransientFile(FileName fileName, int fileFlags, int fileMode);
  82. extern int CloseTransientFile(int fd);
  83. /* If you've really really gotta have a plain kernel FD, use this */
  84. extern int BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
  85. /* Miscellaneous support routines */
  86. extern void InitFileAccess(void);
  87. extern void set_max_safe_fds(void);
  88. extern void closeAllVfds(void);
  89. extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
  90. extern bool TempTablespacesAreSet(void);
  91. extern Oid GetNextTempTableSpace(void);
  92. extern void AtEOXact_Files(void);
  93. extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
  94. SubTransactionId parentSubid);
  95. extern void RemovePgTempFiles(void);
  96. extern int pg_fsync(int fd);
  97. extern int pg_fsync_no_writethrough(int fd);
  98. extern int pg_fsync_writethrough(int fd);
  99. extern int pg_fdatasync(int fd);
  100. extern void pg_flush_data(int fd, off_t offset, off_t amount);
  101. extern void fsync_fname(const char *fname, bool isdir);
  102. extern int durable_rename(const char *oldfile, const char *newfile, int loglevel);
  103. extern int durable_link_or_rename(const char *oldfile, const char *newfile, int loglevel);
  104. extern void SyncDataDirectory(void);
  105. /* Filename components for OpenTemporaryFile */
  106. #define PG_TEMP_FILES_DIR "pgsql_tmp"
  107. #define PG_TEMP_FILE_PREFIX "pgsql_tmp"
  108. #endif /* FD_H */