1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* fd.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Virtual file descriptor definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1999-07-17 22:18:55 +02:00
|
|
|
* $Id: fd.h,v 1.17 1999/07/17 20:18:34 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* calls:
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
|
|
|
* File {Close, Read, Write, Seek, Tell, Sync}
|
|
|
|
* {File Name Open, Allocate, Free} File
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* These are NOT JUST RENAMINGS OF THE UNIX ROUTINES.
|
1999-05-09 02:52:08 +02:00
|
|
|
* Use them for all file activity...
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* File fd;
|
1999-05-09 02:52:08 +02:00
|
|
|
* fd = FilePathOpenFile("foo", O_RDONLY);
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* AllocateFile();
|
|
|
|
* FreeFile();
|
1999-05-09 02:52:08 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The BufFile routines provide a partial replacement for stdio. Currently
|
|
|
|
* they only support buffered access to a virtual file, without any of
|
|
|
|
* stdio's formatting features. That's enough for immediate needs, but
|
|
|
|
* the set of facilities could be expanded if necessary.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef FD_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define FD_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FileSeek uses the standard UNIX lseek(2) flags.
|
|
|
|
*/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef char *FileName;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef int File;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-05-09 02:52:08 +02:00
|
|
|
/* BufFile is an opaque type whose details are not known outside fd.c. */
|
|
|
|
|
|
|
|
typedef struct BufFile BufFile;
|
|
|
|
|
|
|
|
/* why is this here? fd.c doesn't want it ... */
|
1997-09-07 07:04:48 +02:00
|
|
|
struct pgstat
|
|
|
|
{ /* just the fields we need from stat
|
|
|
|
* structure */
|
1997-09-08 04:41:22 +02:00
|
|
|
int st_ino;
|
|
|
|
int st_mode;
|
|
|
|
unsigned int st_size;
|
|
|
|
unsigned int st_sizehigh; /* high order bits */
|
1996-08-28 03:59:28 +02:00
|
|
|
/* 2^64 == 1.8 x 10^20 bytes */
|
1997-09-08 04:41:22 +02:00
|
|
|
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.. */
|
1996-08-28 03:59:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in fd.c
|
|
|
|
*/
|
1999-05-09 02:52:08 +02:00
|
|
|
|
|
|
|
/* Operations on virtual Files --- equivalent to Unix kernel file ops */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern File FileNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
|
|
|
extern File PathNameOpenFile(FileName fileName, int fileFlags, int fileMode);
|
1999-05-09 02:52:08 +02:00
|
|
|
extern File OpenTemporaryFile(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
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 int FileTruncate(File file, int offset);
|
|
|
|
extern int FileSync(File file);
|
1999-05-09 02:52:08 +02:00
|
|
|
|
|
|
|
/* Operations that allow use of regular stdio --- USE WITH CAUTION */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern FILE *AllocateFile(char *name, char *mode);
|
|
|
|
extern void FreeFile(FILE *);
|
1999-05-09 02:52:08 +02:00
|
|
|
|
|
|
|
/* Operations on BufFiles --- a very incomplete emulation of stdio
|
|
|
|
* atop virtual Files...
|
|
|
|
*/
|
|
|
|
extern BufFile *BufFileCreate(File file);
|
1999-05-26 00:43:53 +02:00
|
|
|
extern void BufFileClose(BufFile *file);
|
|
|
|
extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
|
|
|
|
extern size_t BufFileWrite(BufFile *file, void *ptr, size_t size);
|
|
|
|
extern long BufFileSeek(BufFile *file, long offset, int whence);
|
1999-05-09 02:52:08 +02:00
|
|
|
|
|
|
|
/* Miscellaneous support routines */
|
|
|
|
extern int FileNameUnlink(char *filename);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void closeAllVfds(void);
|
1999-05-09 02:52:08 +02:00
|
|
|
extern void AtEOXact_Files(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int pg_fsync(int fd);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* FD_H */
|