]> granicus.if.org Git - postgresql/blob - src/include/storage/fd.h
Code review for holdable-cursors patch. Fix error recovery, memory
[postgresql] / src / include / storage / fd.h
1 /*-------------------------------------------------------------------------
2  *
3  * fd.h
4  *        Virtual file descriptor definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: fd.h,v 1.38 2003/04/29 03:21:30 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14
15 /*
16  * calls:
17  *
18  *      File {Close, Read, Write, Seek, Tell, MarkDirty, Sync}
19  *      {File 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 = FilePathOpenFile("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 #ifndef FD_H
36 #define FD_H
37
38 /*
39  * FileSeek uses the standard UNIX lseek(2) flags.
40  */
41
42 typedef char *FileName;
43
44 typedef int File;
45
46
47 /* GUC parameter */
48 extern int      max_files_per_process;
49
50
51 /*
52  * prototypes for functions in fd.c
53  */
54
55 /* Operations on virtual Files --- equivalent to Unix kernel file ops */
56 extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
57 extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
58 extern File OpenTemporaryFile(bool interXact);
59 extern void FileClose(File file);
60 extern void FileUnlink(File file);
61 extern int      FileRead(File file, char *buffer, int amount);
62 extern int      FileWrite(File file, char *buffer, int amount);
63 extern long FileSeek(File file, long offset, int whence);
64 extern int      FileTruncate(File file, long offset);
65
66 /* Operations that allow use of regular stdio --- USE WITH CAUTION */
67 extern FILE *AllocateFile(char *name, char *mode);
68 extern void FreeFile(FILE *);
69
70 /* If you've really really gotta have a plain kernel FD, use this */
71 extern int      BasicOpenFile(FileName fileName, int fileFlags, int fileMode);
72
73 /* Miscellaneous support routines */
74 extern void closeAllVfds(void);
75 extern void AtEOXact_Files(void);
76 extern void RemovePgTempFiles(void);
77 extern int      pg_fsync(int fd);
78 extern int      pg_fdatasync(int fd);
79
80 #endif   /* FD_H */