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

Generated on Mon Oct 23 13:22:59 2006 for GigaBASE by doxygen1.2.18