00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #pragma once
00031 #ifndef __TABLE_MS_H__
00032 #define __TABLE_MS_H__
00033
00034 #include "defs_ms.h"
00035
00036 #define MS_TABLE_FILE_MAGIC 0x1234ABCD
00037 #define MS_TABLE_FILE_VERSION 1
00038 #define MS_TABLE_FILE_HEAD_SIZE 128
00039
00040 class MSOpenTable;
00041 class MSDatabase;
00042 class CSHTTPOutputStream;
00043
00044 typedef struct MSTableHead {
00045 CSDiskValue4 th_magic_4;
00046 CSDiskValue2 th_version_2;
00047 CSDiskValue2 th_head_size_2;
00048 CSDiskValue8 th_free_list_8;
00049
00050
00051 CSDiskValue4 th_del_time_4;
00052 CSDiskValue4 th_temp_log_id_4;
00053 CSDiskValue4 th_temp_log_offset_4;
00054
00055 CSDiskValue4 th_reserved_4;
00056 } MSTableHeadRec, *MSTableHeadPtr;
00057
00058
00059 typedef struct MSTableBlob {
00060 CSDiskValue1 tb_status_1;
00061
00062
00063 CSDiskValue3 tb_repo_id_3;
00064 CSDiskValue6 tb_offset_6;
00065 CSDiskValue2 tb_header_size_2;
00066
00067 CSDiskValue6 tb_size_6;
00068 CSDiskValue4 tb_auth_code_4;
00069 } MSTableBlobRec, *MSTableBlobPtr;
00070
00071 typedef struct MSTableFreeBlob {
00072 CSDiskValue4 tf_null_4;
00073 CSDiskValue6 tf_next_6;
00074 } MSTableFreeBlobRec, *MSTableFreeBlobPtr;
00075
00076 class MSTable : public CSSharedRefObject {
00077 public:
00078 CSString *myTableName;
00079 uint32_t myTableID;
00080 MSDatabase *myDatabase;
00081
00082 MSTable();
00083 virtual ~MSTable();
00084
00085 CSPath *getTableFile(const char *table_name, bool to_delete);
00086
00087 CSPath *getTableFile();
00088
00089 CSFile *openTableFile();
00090
00091 void prepareToDelete();
00092
00093 uint64_t createBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00094
00095 uint64_t findBlobHandle(MSOpenTable *otab, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00096
00097 void setBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint64_t size, uint16_t head_size, uint32_t auth_code);
00098
00099 void updateBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t offset, uint16_t head_size);
00100
00101 bool readBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t *auth_code, uint32_t *repo_id, uint64_t *offset, uint64_t *data_size, uint16_t *head_size, bool throw_error);
00102
00103 void freeBlobHandle(MSOpenTable *otab, uint64_t blob_id, uint32_t repo_id, uint64_t file_offset, uint32_t auth_code);
00104
00105
00106 virtual CSObject *getKey();
00107 virtual int compareKey(CSObject *);
00108 virtual uint32_t hashKey();
00109
00110 off64_t getTableFileSize() { return iTableFileSize; }
00111 CSString *getTableName();
00112 bool isToDelete() { return iToDelete; }
00113 void getDeleteInfo(uint32_t *log, uint32_t *offs, time_t *tim);
00114 bool isNoTable() { return myTableName->length() == 0; }
00115
00116 private:
00117 off64_t iTableFileSize;
00118 size_t iTableHeadSize;
00119 off64_t iFreeList;
00120 bool iToDelete;
00121 uint32_t iTabDeleteTime;
00122 uint32_t iTabTempLogID;
00123 uint32_t iTabTempLogOffset;
00124
00125 public:
00126 static MSTable *newTable(uint32_t tab_id, CSString *name, MSDatabase *db, off64_t file_size, bool to_delete);
00127
00128 static MSTable *newTable(uint32_t tab_id, const char *name, MSDatabase *db, off64_t file_size, bool to_delete);
00129 };
00130
00131 #endif