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

file.h

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

Generated on Thu Feb 12 18:46:27 2004 for GigaBASE by doxygen 1.3.5