• Main Page
  • Classes
  • Files
  • File List

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

Generated on Mon Aug 23 2010 00:04:01 for GigaBASE by  doxygen 1.7.1