aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/fd.h
blob: da28b031bb8ab777f330ced58a748fdc86c8f183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*-------------------------------------------------------------------------
 *
 * fd.h--
 *    Virtual file descriptor definitions.
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 * $Id: fd.h,v 1.1.1.1 1996/07/09 06:21:52 scrappy Exp $
 *
 *-------------------------------------------------------------------------
 */
/*
 * calls:
 * 
 *  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...
 *
 *  fd = FilePathOpenFile("foo", O_RDONLY);
 *  File fd;
 *
 * use AllocateFile if you need a file descriptor in some other context.
 * it will make sure that there is a file descriptor free
 *
 * use FreeFile to let the virtual file descriptor package know that 
 * there is now a free fd (when you are done with it)
 *
 *  AllocateFile();
 *  FreeFile();
 */
#ifndef	FD_H
#define FD_H

/*
 * FileOpen uses the standard UNIX open(2) flags.
 */
#include <fcntl.h>	/* for O_ on most */
#ifndef O_RDONLY
#include <sys/file.h>	/* for O_ on the rest */
#endif /* O_RDONLY */

/*
 * FileSeek uses the standard UNIX lseek(2) flags.
 */
#ifndef WIN32
#include <unistd.h>	/* for SEEK_ on most */
#else
#ifndef SEEK_SET
#include <stdio.h>	/* for SEEK_ on the rest */
#endif /* SEEK_SET */
#endif /* WIN32 */

#include "c.h"
#include "storage/block.h"

typedef char   *FileName;

typedef int	File;

/* 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);
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
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 void AllocateFile(void);
extern void FreeFile(void);
extern void closeAllVfds(void);
extern void closeOneVfd(void);

#endif	/* FD_H */