00001
00002
00003
00004
00005
00006
00007
00008
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,
00026 not_supported = -2
00027 };
00028 enum OpenAttributes {
00029 read_only = 0x01,
00030 truncate = 0x02,
00031 sequential = 0x04,
00032 no_buffering = 0x08,
00033 no_sync = 0x10,
00034 shared = 0x20,
00035 write_through = 0x40,
00036 delete_on_close = 0x80
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
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