]> granicus.if.org Git - postgresql/blobdiff - src/include/storage/fd.h
Update copyright for 2009.
[postgresql] / src / include / storage / fd.h
index 9d5a1e819700679a6d266c7cae75bc7a19c9e820..17aa150aa03ea33e2bdc4be9f522ec0c7ddcfa48 100644 (file)
 /*-------------------------------------------------------------------------
  *
- * fd.h--
- *    Virtual file descriptor definitions.
+ * fd.h
+ *       Virtual file descriptor definitions.
  *
  *
- * Copyright (c) 1994, Regents of the University of California
+ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: fd.h,v 1.7 1997/08/18 02:15:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/fd.h,v 1.63 2009/01/01 17:24:01 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
+
 /*
  * calls:
- * 
- *  File {Close, Read, Write, Seek, Tell, Sync}
- *  {File Name Open, Allocate, Free} File
+ *
+ *     File {Close, Read, Write, Seek, Tell, Sync}
+ *     {File Name Open, Allocate, Free} File
  *
  * These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
- * use them for all file activity...
+ * Use them for all file activity...
  *
- *  fd = FilePathOpenFile("foo", O_RDONLY);
- *  File fd;
+ *     File fd;
+ *     fd = FilePathOpenFile("foo", O_RDONLY, 0600);
  *
- * use AllocateFile if you need a file descriptor in some other context.
- * it will make sure that there is a file descriptor free
+ *     AllocateFile();
+ *     FreeFile();
  *
- * use FreeFile to let the virtual file descriptor package know that 
- * there is now a free fd (when you are done with it)
+ * Use AllocateFile, not fopen, if you need a stdio file (FILE*); then
+ * use FreeFile, not fclose, to close it.  AVOID using stdio for files
+ * that you intend to hold open for any length of time, since there is
+ * no way for them to share kernel file descriptors with other files.
  *
- *  AllocateFile();
- *  FreeFile();
+ * Likewise, use AllocateDir/FreeDir, not opendir/closedir, to allocate
+ * open directories (DIR*).
  */
-#ifndef        FD_H
+#ifndef FD_H
 #define FD_H
 
-#include <stdio.h>
+#include <dirent.h>
+
 
 /*
  * FileSeek uses the standard UNIX lseek(2) flags.
  */
 
-typedef char   *FileName;
+typedef char *FileName;
 
-typedef int    File;
+typedef int File;
+
+
+/* GUC parameter */
+extern int     max_files_per_process;
 
-/* originally in libpq-fs.h */
-struct pgstat { /* just the fields we need from stat structure */
-    int st_ino;
-    int st_mode;
-    unsigned int st_size;
-    unsigned int st_sizehigh;  /* high order bits */
-/* 2^64 == 1.8 x 10^20 bytes */
-    int st_uid;
-    int st_atime_s;    /* just the seconds */
-    int st_mtime_s;    /* since SysV and the new BSD both have */
-    int st_ctime_s;    /* usec fields.. */
-};
 
 /*
  * prototypes for functions in fd.c
  */
-extern void FileInvalidate(File file);
-extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
+
+/* Operations on virtual Files --- equivalent to Unix kernel file ops */
 extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
+extern File OpenTemporaryFile(bool interXact);
 extern void FileClose(File file);
-extern void FileUnlink(File file);
-extern int FileRead(File file, char *buffer, int amount);
-extern int FileWrite(File file, char *buffer, int amount);
-extern long FileSeek(File file, long offset, int whence);
-extern long FileTell(File file);
-extern int FileTruncate(File file, int offset);
-extern int FileSync(File file);
-extern int FileNameUnlink(char *filename);
-extern FILE *AllocateFile(char *name, char *mode);
-extern void FreeFile(FILE *);
+extern int     FileRead(File file, char *buffer, int amount);
+extern int     FileWrite(File file, char *buffer, int amount);
+extern int     FileSync(File file);
+extern off_t FileSeek(File file, off_t offset, int whence);
+extern int     FileTruncate(File file, off_t offset);
+
+/* Operations that allow use of regular stdio --- USE WITH CAUTION */
+extern FILE *AllocateFile(const char *name, const char *mode);
+extern int     FreeFile(FILE *file);
+
+/* Operations to allow use of the <dirent.h> library routines */
+extern DIR *AllocateDir(const char *dirname);
+extern struct dirent *ReadDir(DIR *dir, const char *dirname);
+extern int     FreeDir(DIR *dir);
+
+/* If you've really really gotta have a plain kernel FD, use this */
+extern int     BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
+
+/* Miscellaneous support routines */
+extern void InitFileAccess(void);
+extern void set_max_safe_fds(void);
 extern void closeAllVfds(void);
-extern int pg_fsync(int fd);
+extern void SetTempTablespaces(Oid *tableSpaces, int numSpaces);
+extern bool TempTablespacesAreSet(void);
+extern Oid     GetNextTempTableSpace(void);
+extern void AtEOXact_Files(void);
+extern void AtEOSubXact_Files(bool isCommit, SubTransactionId mySubid,
+                                 SubTransactionId parentSubid);
+extern void RemovePgTempFiles(void);
+
+extern int     pg_fsync(int fd);
+extern int     pg_fsync_no_writethrough(int fd);
+extern int     pg_fsync_writethrough(int fd);
+extern int     pg_fdatasync(int fd);
+
+/* Filename components for OpenTemporaryFile */
+#define PG_TEMP_FILES_DIR "pgsql_tmp"
+#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
 
-#endif /* FD_H */
+#endif   /* FD_H */