Main Page   Class Hierarchy   Compound List   File List   Compound 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         not_supported = -2
00027     };
00028     enum OpenAttributes {
00029         read_only    = 0x01, // open file in read-only mode
00030         truncate     = 0x02, // truncate file when opened
00031         sequential   = 0x04, // optimize for sequenial access 
00032         no_buffering = 0x08, // write through 
00033         no_sync      = 0x10, // do not flush data to the disk
00034         shared       = 0x20  // shared access to the file
00035     };
00036     virtual int open(char_t const* fileName, int attr) = 0;
00037     virtual ~dbFile();
00038 
00039     virtual int flush() = 0;
00040     virtual int close() = 0;
00041     
00042     enum LockType { 
00043         lck_shared,
00044         lck_exclusive
00045     };
00046         
00047     virtual int lock(LockType lck) = 0;
00048     virtual int unlock() = 0;
00049 
00050     virtual int setSize(offs_t offs) = 0;
00051 
00052     virtual int write(offs_t pos, void const* ptr, size_t size) = 0;
00053     virtual int read(offs_t pos, void* ptr, size_t size) = 0;
00054 
00055     virtual char_t* errorText(int code, char_t* buf, size_t bufSize) = 0;
00056 };
00057 
00058 
00059 class GIGABASE_DLL_ENTRY dbOSFile : public dbFile {
00060   protected:
00061 #if defined(_WIN32)
00062     HANDLE  fh;
00063 #else
00064     int     fd;
00065 #endif
00066     bool    noSync;
00067     dbMutex mutex;
00068   public:
00069     int open(char_t const* fileName, int attr);
00070     virtual int write(void const* ptr, size_t size);
00071     virtual int read(void* ptr, size_t size);
00072 
00073     virtual int lock(LockType lck);
00074     virtual int unlock();
00075    
00076     dbOSFile();
00077 
00078     int flush();
00079     int close();
00080 
00081     int setSize(offs_t offs);
00082 
00083     int write(offs_t pos, void const* ptr, size_t size);
00084     int read(offs_t pos, void* ptr, size_t size);
00085 
00086     static void* allocateBuffer(size_t bufferSize, bool lock = false);
00087     static void  deallocateBuffer(void* buffer, size_t size = 0, bool unlock = false);
00088     static void  protectBuffer(void* buf, size_t bufSize, bool readonly);
00089 
00090     static size_t ramSize();
00091 
00092     char_t* errorText(int code, char_t* buf, size_t bufSize);
00093 };
00094 
00098 class GIGABASE_DLL_ENTRY dbMultiFile : public dbOSFile {
00099   public:
00100     struct dbSegment {
00101         char_t* name;
00102         offs_t  size;
00103         offs_t  offs;
00104     };
00105 
00106     int open(int nSegments, dbSegment* segments, int attr);
00107 
00108     virtual int setSize(offs_t offs);
00109 
00110     virtual int flush();
00111     virtual int close();
00112 
00113     virtual int write(offs_t pos, void const* ptr, size_t size);
00114     virtual int read(offs_t pos, void* ptr, size_t size);
00115 
00116     dbMultiFile() { segment = NULL; }
00117     ~dbMultiFile() {}
00118 
00119   protected:
00120     class dbFileSegment : public dbOSFile {
00121       public:
00122         offs_t size;
00123         offs_t offs;
00124     };
00125     int            nSegments;
00126     dbFileSegment* segment;
00127 };
00128 
00129 /*
00130  * RAID-1 file. Scattern file blocks between several physical segments
00131  */
00132 class GIGABASE_DLL_ENTRY dbRaidFile : public dbMultiFile {
00133     size_t raidBlockSize;
00134   public:
00135     dbRaidFile(size_t blockSize) { 
00136         raidBlockSize = blockSize;
00137     }
00138 
00139     virtual int setSize(offs_t offs);
00140 
00141     virtual int write(offs_t pos, void const* ptr, size_t size);
00142     virtual int read(offs_t pos, void* ptr, size_t size);
00143 };    
00144 
00145 END_GIGABASE_NAMESPACE
00146 
00147 #endif
00148 
00149 
00150 
00151 

Generated on Thu Feb 14 21:46:03 2008 for GigaBASE by doxygen1.2.18