Main Page | Class Hierarchy | Class List | File List | Class Members

file.h

00001 //-< FILE.H >--------------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     20-Nov-98    K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 30-Jan-99    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // System independent intrface to operating system file
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __FILE_H__
00012 #define __FILE_H__
00013 
00014 BEGIN_GIGABASE_NAMESPACE
00015 
00016 const size_t dbDefaultRaidBlockSize = 1024*1024;
00017 
00021 class GIGABASE_DLL_ENTRY dbFile {
00022   public:
00023     enum ReturnStatus {
00024         ok  = 0,
00025         eof = -1 // number of read/written bytes is smaller than requested
00026     };
00027     enum OpenAttributes {
00028         read_only    = 0x01, // open file in read-only mode
00029         truncate     = 0x02, // truncate file when opened
00030         sequential   = 0x04, // optimize for sequenial access 
00031         no_buffering = 0x08, // write through 
00032         no_sync      = 0x10  // do not flush data to the disk
00033     };
00034     virtual int open(char_t const* fileName, int attr) = 0;
00035     virtual ~dbFile();
00036 
00037     virtual int flush() = 0;
00038     virtual int close() = 0;
00039 
00040     virtual int setSize(offs_t offs) = 0;
00041 
00042     virtual int write(offs_t pos, void const* ptr, size_t size) = 0;
00043     virtual int read(offs_t pos, void* ptr, size_t size) = 0;
00044 
00045     virtual char_t* errorText(int code, char_t* buf, size_t bufSize) = 0;
00046 };
00047 
00048 
00049 class GIGABASE_DLL_ENTRY dbOSFile : public dbFile {
00050   protected:
00051 #if defined(_WIN32)
00052     HANDLE  fh;
00053 #else
00054     int     fd;
00055 #endif
00056     bool    noSync;
00057     dbMutex mutex;
00058   public:
00059     int open(char_t const* fileName, int attr);
00060     virtual int write(void const* ptr, size_t size);
00061     virtual int read(void* ptr, size_t size);
00062 
00063     
00064     dbOSFile();
00065 
00066     int flush();
00067     int close();
00068 
00069     int setSize(offs_t offs);
00070 
00071     int write(offs_t pos, void const* ptr, size_t size);
00072     int read(offs_t pos, void* ptr, size_t size);
00073 
00074     static void* allocateBuffer(size_t bufferSize, bool lock = false);
00075     static void  deallocateBuffer(void* buffer, size_t size = 0, bool unlock = false);
00076     static void  protectBuffer(void* buf, size_t bufSize, bool readonly);
00077 
00078     static size_t ramSize();
00079 
00080     char_t* errorText(int code, char_t* buf, size_t bufSize);
00081 };
00082 
00086 class GIGABASE_DLL_ENTRY dbMultiFile : public dbOSFile {
00087   public:
00088     struct dbSegment {
00089         char_t* name;
00090         offs_t  size;
00091         offs_t  offs;
00092     };
00093 
00094     int open(int nSegments, dbSegment* segments, int attr);
00095 
00096     virtual int setSize(offs_t offs);
00097 
00098     virtual int flush();
00099     virtual int close();
00100 
00101     virtual int write(offs_t pos, void const* ptr, size_t size);
00102     virtual int read(offs_t pos, void* ptr, size_t size);
00103 
00104     dbMultiFile() { segment = NULL; }
00105     ~dbMultiFile() {}
00106 
00107   protected:
00108     class dbFileSegment : public dbOSFile {
00109       public:
00110         offs_t size;
00111         offs_t offs;
00112     };
00113     int            nSegments;
00114     dbFileSegment* segment;
00115 };
00116 
00117 /*
00118  * RAID-1 file. Scattern file blocks between several physical segments
00119  */
00120 class GIGABASE_DLL_ENTRY dbRaidFile : public dbMultiFile {
00121     size_t raidBlockSize;
00122   public:
00123     dbRaidFile(size_t blockSize) { 
00124         raidBlockSize = blockSize;
00125     }
00126 
00127     virtual int setSize(offs_t offs);
00128 
00129     virtual int write(offs_t pos, void const* ptr, size_t size);
00130     virtual int read(offs_t pos, void* ptr, size_t size);
00131 };    
00132 
00133 END_GIGABASE_NAMESPACE
00134 
00135 #endif
00136 
00137 
00138 
00139 

Generated on Thu Nov 24 23:14:29 2005 for GigaBASE by doxygen 1.3.5