eyedbsm.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDBSM_EYEDBSM_H
00026 #define _EYEDBSM_EYEDBSM_H
00027 
00028 #include <stdio.h>
00029 #include <stdarg.h>
00030 #include <sys/stat.h>
00031 
00032 namespace eyedbsm {
00033 
00039   static const unsigned int MAX_ROOT_KEY = 16;
00040   static const unsigned int MAX_ROOT_DATA = 64;
00041   static const unsigned int MAX_DATAFILES = 512;
00042   static const unsigned int MAX_DATASPACES = 512;
00043   static const unsigned int MAX_DAT_PER_DSP = 32;
00044 
00045   static const unsigned int Oid_DBID = 10;
00046   static const unsigned int Oid_UNIQUE = 22;
00047 
00048   static const unsigned int L_NAME = 31;
00049 
00050   static const unsigned int L_FILENAME = 256;
00051 
00052   static const unsigned int MIN_SIZE_SLOT = 8;
00053   static const unsigned int MAX_SIZE_SLOT = 4096;
00054 
00055   static const unsigned int VOLREAD = 0x100;
00056   static const unsigned int VOLRW = 0x200;
00057   static const unsigned int LOCAL = 0x004; 
00058   static const unsigned int STANDALONE = 0x008;
00059   static const unsigned int MAX_DBID = ((1 << (Oid_DBID))-1);
00060   static const unsigned int PROT_NAME = 32;
00061 
00062   static const unsigned long INVALID_UID = ~0UL;
00063 
00064   static const short DefaultDspid = (short)0x7fff;
00065 
00066   typedef unsigned int NS;
00067 
00068   class Oid {
00069 
00070   public:
00071     typedef unsigned int NX;
00072     typedef unsigned int DbID;
00073     typedef unsigned int Unique;
00074 
00075     static const size_t SIZE;
00076     static const Oid::NX INVALID_NX;
00077     static const Oid nullOid;
00078 
00079     void setNX(Oid::NX _nx) {nx = _nx;}
00080     Oid::NX getNX() const {return nx;}
00081 
00082     void setDbID(Oid::DbID _dbid) {dbid = _dbid;}
00083     Oid::DbID getDbID() const {return dbid;}
00084 
00085     void setUnique(Oid::Unique _unique) {unique = _unique;}
00086     Oid::Unique getUnique() const {return unique;}
00087 
00088   private:
00089     Oid::NX nx;
00090     unsigned int dbid:Oid_DBID, unique:Oid_UNIQUE;
00091 
00092   public:
00093     static Oid makeNullOid();
00094   };
00095 
00096   enum Boolean {
00097     False = 0,
00098     True  = 1
00099   };
00100 
00101   enum MapHints {
00102     WholeMap = 0x111,
00103     SegmentMap = 0x222
00104   };
00105 
00106   struct OpenHints {
00107     eyedbsm::MapHints maph;
00108     unsigned int mapwide; /* in page; 0 if default */
00109   };
00110 
00111   struct ObjectLocation {
00112     short datid;
00113     short dspid;
00114     eyedbsm::Boolean is_valid;
00115     unsigned int size;
00116     NS slot_start_num;
00117     NS slot_end_num;
00118     unsigned int dat_start_pagenum;
00119     unsigned int dat_end_pagenum;
00120     unsigned int omp_start_pagenum;
00121     unsigned int omp_end_pagenum;
00122     unsigned int dmp_start_pagenum;
00123     unsigned int dmp_end_pagenum;
00124   };
00125   
00126   enum MapType {
00127     BitmapType,
00128     LinkmapType,
00129     DefaultMapType = eyedbsm::BitmapType
00130   };
00131 
00132   enum DatType {
00133     LogicalOidType = 0x100,
00134     PhysicalOidType
00135   };
00136 
00137   struct Datafile {
00138     char file[L_FILENAME];
00139     char name[L_NAME+1];
00140     unsigned long long maxsize; /* in Kbytes */
00141     short mtype; /* was eyedbsm::MapType */
00142     unsigned int sizeslot;
00143     short dspid;
00144     int extflags;
00145     short dtype; /* eyedbsm::DatType */
00146   };
00147 
00148   struct DatafileInfo {
00149     unsigned short datid;
00150     eyedbsm::Datafile datafile;
00151     Oid::NX objcnt;
00152     NS slotcnt;
00153     NS busyslotcnt;
00154     unsigned long long totalsize;
00155     unsigned int avgsize;
00156     NS lastbusyslot;
00157     NS lastslot;
00158     unsigned long long busyslotsize;
00159     unsigned long long datfilesize;
00160     unsigned long long datfileblksize;
00161     unsigned long long dmpfilesize;
00162     unsigned long long dmpfileblksize;
00163     NS curslot;
00164     unsigned long long defragmentablesize;
00165     NS slotfragcnt;
00166     double used;
00167   };
00168 
00169   struct Dataspace {
00170     char name[L_NAME+1];
00171     unsigned int ndat;
00172     short datid[MAX_DAT_PER_DSP];
00173   };
00174 
00175   struct DbCreateDescription {
00176     Oid::NX nbobjs;
00177     unsigned int dbid;
00178     unsigned int ndat;
00179     eyedbsm::Datafile dat[MAX_DATAFILES];
00180     unsigned int ndsp;
00181     eyedbsm::Dataspace dsp[MAX_DATASPACES];
00182     unsigned long long dbsfilesize;    /* used with DbInfo only */
00183     unsigned long long dbsfileblksize; /* used with DbInfo only */
00184     unsigned long long ompfilesize;    /* used with DbInfo only */
00185     unsigned long long ompfileblksize; /* used with DbInfo only */
00186     unsigned long long shmfilesize;    /* used with DbInfo only */
00187     unsigned long long shmfileblksize; /* used with DbInfo only */
00188   };
00189 
00190   typedef DbCreateDescription DbInfoDescription;
00191 
00192   struct DbRelocateDescription {
00193     unsigned int ndat;
00194     char file[MAX_DATAFILES][L_FILENAME];
00195   };
00196 
00197   struct DbMoveDescription {
00198     char dbfile[L_FILENAME];
00199     eyedbsm::DbCreateDescription dcr;
00200   };
00201 
00202   typedef DbMoveDescription DbCopyDescription;
00203 
00204   struct Protection {
00205     unsigned short r, w;
00206   };
00207 
00208   struct ProtectionAtom {
00209     unsigned int uid;
00210     eyedbsm::Protection prot;
00211   };
00212 
00213   struct ProtectionDescription {
00214     char name[PROT_NAME];
00215     unsigned int nprot;
00216     eyedbsm::ProtectionAtom desc[1];
00217   };
00218 
00219   struct DbProtectionDescription {
00220     unsigned int uid;
00221     Protection prot;
00222   };
00223 
00224   struct DbHandle;
00225   struct IndexId;
00226   struct Cursor;
00227   struct DbLock;
00228 
00229   enum LockMode {
00230     DefaultLock,
00231     LockN,  /* no lock */
00232     LockX,  /* exclusive */
00233     LockSX, /* shared/exclusive */
00234     LockS,  /* shared */
00235     LockP,  /* private */
00236     LockE   /* lock error */
00237   };
00238 
00239   enum TransactionMode {
00240     TransactionOff = 1,  /* no rollback is possible */
00241     TransactionOn  = 2
00242   };
00243 
00244   /* lockmode: S means shared, X means exclusive, SX means shared/exclusive */
00245   enum ObjectLockMode {
00246     ReadSWriteS = 1, /* read shared; write shared */
00247     ReadSWriteSX,    /* read shared; write shared/exclusive */  
00248     ReadSWriteX,     /* read shared; write exclusive */  
00249     ReadSXWriteSX,   /* read shared/exclusive; write shared/exclusive */
00250     ReadSXWriteX,    /* read shared/exclusive; write exclusive */
00251     ReadXWriteX,     /* read exclusive; write exclusive */
00252     ReadNWriteS,     /* read no lock; write shared */
00253     ReadNWriteSX,    /* read no lock; write shared/exclusive */
00254     ReadNWriteX,     /* read no lock; write exclusive */
00255     ReadNWriteN,     /* read no lock; write no lock */
00256     DatabaseW,       /* database exclusive for writing */
00257     DatabaseRW,      /* database exclusive for reading and writing */
00258     DatabaseWtrans   /* database exclusive for writing transaction */
00259   };
00260 
00261   enum RecoveryMode {
00262     RecoveryOff = 3, /* prevents from remote client failure */
00263     RecoveryPartial, /* plus prevents from local client and server failure */
00264     RecoveryFull     /* plus prevents from OS failure */
00265   };
00266 
00267   struct TransactionParams {
00268     TransactionMode trsmode;
00269     ObjectLockMode lockmode;
00270     RecoveryMode recovmode;
00271     unsigned int magorder;     /* estimated object cardinality in trans */
00272     unsigned int ratioalrt;    /* error returned if ratio != 0 &&
00273                                   trans object number > ratioalrt * magorder  */
00274     unsigned int wait_timeout; /* in seconds */
00275   };
00276 
00277   static const TransactionParams DEFAULT_TRANSACTION_PARAMS = {
00278     eyedbsm::TransactionOn,
00279     eyedbsm::ReadNWriteSX,
00280     eyedbsm::RecoveryFull,
00281     0,
00282     0,
00283     30
00284   };
00285 
00286   enum Error {
00287     SUCCESS = 0,
00288     ERROR,
00289     SYS_ERROR,
00290     CONNECTION_FAILURE,
00291     SERVER_FAILURE,
00292     CANNOT_LOCK_SHMFILE,
00293     DB_ALREADY_LOCK_BY_A_SERVER,
00294     INVALID_DBID,
00295     INVALID_SIZESLOT,
00296     INVALID_NBSLOTS,
00297     INVALID_NBOBJS,
00298     INVALID_MAXSIZE,
00299     INVALID_MAPTYPE,
00300     DATABASE_CREATION_ERROR,
00301     DATABASE_ACCESS_DENIED,
00302     DATABASE_OPEN_FAILED,
00303     INVALID_DATAFILE_CNT,
00304     INVALID_DATASPACE_CNT,
00305     INVALID_DATAFILE_CNT_IN_DATASPACE,
00306     INVALID_DATASPACE,
00307     INVALID_DBFILE,
00308     INVALID_DBFILE_ACCESS,
00309     INVALID_SHMFILE,
00310     INVALID_SHMFILE_ACCESS,
00311     INVALID_OBJMAP_ACCESS,
00312     INVALID_DATAFILE,
00313     INVALID_DMPFILE,
00314     INVALID_DATAFILEMAXSIZE,
00315     INVALID_FILES_COPY,
00316     INVALID_DBFILES_COPY,
00317     INVALID_DATAFILES_COPY,
00318     INVALID_SHMFILES_COPY,
00319     INVALID_OBJMAPFILES_COPY,
00320     DBFILES_IDENTICAL,
00321     DATAFILES_IDENTICAL,
00322     DBFILE_ALREADY_EXISTS,
00323     SHMFILE_ALREADY_EXISTS,
00324     OBJMAPFILE_ALREADY_EXISTS,
00325     DATAFILE_ALREADY_EXISTS,
00326     SIZE_TOO_LARGE,
00327     WRITE_FORBIDDEN,
00328     CONN_RESET_BY_PEER,
00329     LOCK_TIMEOUT,
00330     FATAL_MUTEX_LOCK_TIMEOUT,
00331     BACKEND_INTERRUPTED,
00332     INVALID_TRANSACTION_MODE,
00333     RW_TRANSACTION_NEEDED,
00334     TRANSACTION_NEEDED,
00335     TRANSACTION_LOCKING_FAILED,
00336     TRANSACTION_UNLOCKING_FAILED,
00337     TOO_MANY_TRANSACTIONS,
00338     TRANSACTION_TOO_MANY_NESTED,
00339     DEADLOCK_DETECTED,
00340     INVALID_FLAG,
00341     INVALID_DB_HANDLE,
00342     MAP_ERROR,
00343     TOO_MANY_OBJECTS,
00344     INVALID_OBJECT_SIZE,
00345     NO_DATAFILESPACE_LEFT,
00346     NO_SHMSPACE_LEFT,
00347     INVALID_SIZE,
00348     INVALID_OFFSET,
00349     INVALID_OID,
00350     INVALID_ROOT_ENTRY_SIZE,
00351     INVALID_ROOT_ENTRY_KEY,
00352     INVALID_READ_ACCESS,
00353     INVALID_WRITE_ACCESS,
00354     OBJECT_PROTECTED,
00355     PROTECTION_INVALID_UID,
00356     PROTECTION_DUPLICATE_UID,
00357     PROTECTION_DUPLICATE_NAME,
00358     PROTECTION_NOT_FOUND,
00359     ROOT_ENTRY_EXISTS,
00360     TOO_MANY_ROOT_ENTRIES,
00361     ROOT_ENTRY_NOT_FOUND,
00362     PROT_NAME_TOO_LONG,
00363     NOTIMPLEMENTED,
00364     NO_SETUID_PRIVILEGE,
00365     NOT_YET_IMPLEMENTED,
00366     COMPATIBILITY_ERROR,
00367     INTERNAL_ERROR,
00368     FATAL_ERROR,
00369     N_ERROR
00370   };
00371 
00372   struct StatusRec {
00373     Error err;
00374     char *err_msg;
00375   };
00376 
00377   enum OP {
00378     CreateOP  = 0x1,
00379     ReadOP    = 0x2,
00380     WriteOP   = 0x4,
00381     SizeModOP = 0x8,
00382     DeleteOP  = 0x10,
00383     SizeGetOP = 0x20,
00384     LockNOP   = 0x40,
00385     LockSOP   = 0x80,
00386     LockXOP   = 0x100,
00387     LockSXOP  = 0x200,
00388     LockPOP   = 0x400,
00389     AllOP     = ~0
00390   };
00391 
00392   struct RegisterEntry {
00393     Oid oid;
00394     OP op;
00395     int create_size;
00396     int start_rw, length_rw;
00397     int sizemod_size;
00398   };
00399 
00400   struct Register {
00401     unsigned int oid_cnt;
00402     RegisterEntry *entries;
00403   };
00404 
00405   typedef const StatusRec *Status;
00406 
00407   /* function declarations */
00408 
00409   extern Status
00410   init(),
00411     release(),
00412 
00413     // functional API : should disapear
00414     dbCreate(const char *dbfile, unsigned int version,
00415              const DbCreateDescription *dbc, mode_t file_mask, const char *file_group),
00416     dbDelete(const char *dbfile),
00417     dbMove(const char *dbfile, const DbMoveDescription *dmv),
00418     dbCopy(const char *dbfile, const DbCopyDescription *dcp),
00419 
00420     dbOpen(const char *dbfile, int flags,
00421            const OpenHints *hints, int uid, unsigned int *pversion,
00422            DbHandle **dbh),
00423     dbClose(const DbHandle *dbh),
00424 
00425     dbInfo(const char *dbfile, DbInfoDescription *info),
00426 
00427     transactionBegin(DbHandle *dbh, 
00428                      const TransactionParams *params),
00429     transactionCommit(DbHandle *dbh),
00430     transactionAbort(DbHandle *dbh),
00431 
00432     transactionParamsSet(DbHandle const *dbh,
00433                          const TransactionParams *params),
00434 
00435     transactionParamsGet(DbHandle const *dbh,
00436                          TransactionParams *params),
00437 
00438     dbRelocate(const char *dbfile, const DbRelocateDescription *rel),
00439 
00440     rootEntrySet(DbHandle const *dbh, char const *const key,
00441                  void const *const data, unsigned int size, Boolean create),
00442     rootEntryGet(DbHandle const *dbh, char const *const key,
00443                  void *data, unsigned int maxsize),
00444     rootEntryDelete(DbHandle const *dbh, char const *const key),
00445 
00446     objectCreate(DbHandle const *dbh, void const *const object,
00447                  unsigned int size, short dspid, Oid *oid),
00448     objectDelete(DbHandle const *dbh, Oid const *const oid),
00449     objectWrite(DbHandle const *dbh, int start, int length,
00450                 void const *const object, Oid const *const oid),
00451     objectWriteCache(DbHandle const *dbh, int start,
00452                      void const *const object, Oid const *const oid),
00453     objectRead(DbHandle const *dbh, int start, int length, void *object,
00454                LockMode lockmode, short *pdatid, unsigned int *psize,
00455                Oid const *const oid),
00456     objectReadNoCopy(DbHandle const *dbh, int start, int length,
00457                      void *object,
00458                      LockMode lockmode, short *pdatid, unsigned int *psize,
00459                      Oid const *const oid),
00460     objectReadCache(DbHandle const *dbh, int start, void **object,
00461                     LockMode lockmode, Oid const *const oid),
00462     objectSizeGet(DbHandle const *dbh, unsigned int *size,
00463                   LockMode lockmode, Oid const *const oid),
00464 
00465     objectCheckAccess(DbHandle const *dbh, Boolean write,
00466                       Oid const *const oid, Boolean *access),
00467 
00468     objectLocationGet(DbHandle const *dbh, const Oid *oid,
00469                       ObjectLocation *objloc),
00470 
00471     objectsLocationGet(DbHandle const *dbh, const Oid *oid,
00472                        ObjectLocation *objloc, unsigned int oid_cnt),
00473 
00474     objectMoveDat(DbHandle const *dbh, Oid const *const oid,
00475                   short datid),
00476 
00477     objectsMoveDat(DbHandle const *dbh, Oid const *const oid,
00478                    unsigned int oid_cnt, short datid),
00479 
00480     objectMoveDsp(DbHandle const *dbh, Oid const *const oid,
00481                   short dspid),
00482 
00483     objectsMoveDsp(DbHandle const *dbh, Oid const *const oid,
00484                    unsigned int oid_cnt, short dspid),
00485 
00486     objectSizeModify(DbHandle const *dbh, unsigned int size, Boolean copy,
00487                      Oid const *const oid),
00488 
00489     objectLock(DbHandle const *dbh, Oid const *const oid,
00490                LockMode mode, LockMode *rmode),
00491 
00492     objectGetLock(DbHandle const *dbh, Oid const *const oid,
00493                   LockMode *rmode),
00494 
00495     objectDownLock(DbHandle const *dbh, Oid const *const oid),
00496 
00497     registerStart(DbHandle const *dbh, unsigned reg_mask),
00498     registerClear(DbHandle const *dbh),
00499     registerEnd(DbHandle const *dbh),
00500     registerGet(DbHandle const *dbh, Register **),
00501 
00502     firstOidDatGet(DbHandle const *dbh, short datid, Oid *oid,
00503                    Boolean *found),
00504     nextOidDatGet(DbHandle const *dbh, short datid,
00505                   Oid const *const baseoid, Oid *nextoid,
00506                   Boolean *found),
00507 
00508     privilegeInit(void),
00509     privilegeAcquire(void),
00510     privilegeRelease(void),
00511     suserUnset(DbHandle *dbh),
00512 
00513     statusPrint(Status status, const char *fmt, ...),
00514 
00515     statusMake(Error, const char *, ...),
00516     statusMake_s(Error),
00517 
00518     datCreate(DbHandle const *dbh, const char *file, const char *name,
00519               unsigned long long maxsize, MapType mtype, unsigned int sizeslot,
00520               DatType type, mode_t file_mask, const char *file_group),
00521 
00522     datMove(DbHandle const *dbh, const char *datfile,
00523             const char *newdatfile),
00524 
00525     datDelete(DbHandle const *dbh, const char *datfile),
00526 
00527     datResize(DbHandle const *dbh, const char *datfile,
00528               unsigned long long newmaxsize),
00529 
00530     datMoveObjects(DbHandle const *dbh, const char *dat_src,
00531                    const char *dat_dest),
00532                     
00533     datCheck(DbHandle const *dbh, const char *datfile,
00534              short *datid, short *dspid),
00535                     
00536     datResetCurSlot(DbHandle const *dbh, const char *datfile),
00537 
00538     datDefragment(DbHandle const *dbh, const char *datfile, mode_t file_mask, const char *file_group),
00539 
00540     datRename(DbHandle const *dbh, const char *datfile, const char *name),
00541 
00542     datGetInfo(DbHandle const *dbh, const char *datfile, DatafileInfo *info),
00543 
00544     datGetDspid(DbHandle const *dbh, short datid, short *dspid),
00545 
00546     dspSetDefault(DbHandle const *dbh, const char *dataspace),
00547 
00548     dspGetDefault(DbHandle const *dbh, short *dspid),
00549 
00550     dspCreate(DbHandle const *dbh, const char *dataspace,
00551               const char **datfiles, unsigned int datfile_cnt),
00552 
00553     dspUpdate(DbHandle const *dbh, const char *dataspace,
00554               const char **datfiles, unsigned int datfile_cnt),
00555 
00556     dspDelete(DbHandle const *dbh, const char *dataspace),
00557     dspRename(DbHandle const *dbh, const char *dataspace,
00558               const char *dataspace_new),
00559 
00560     dspCheck(DbHandle const *dbh, const char *dataspace, short *dspid,
00561              short datid[], unsigned int *ndat),
00562                     
00563     dspSetCurDat(DbHandle const *dbh, const char *dataspace,
00564                  const char *datfile),
00565     dspGetCurDat(DbHandle const *dbh, const char *dataspace, short *datid),
00566 
00567     objectNumberSet(DbHandle const *dbh, Oid::NX maxobjs),
00568 
00569     protectionCreate(DbHandle const *dbh,
00570                      ProtectionDescription const *desc,
00571                      Oid *oid),
00572 
00573     protectionDelete(DbHandle const *dbh, Oid const *const oid),
00574 
00575     protectionModify(DbHandle const *dbh,
00576                      ProtectionDescription const *desc,
00577                      Oid const *oid),
00578 
00579     protectionGetByName(DbHandle const *dbh,
00580                         char const *name,
00581                         ProtectionDescription **desc,
00582                         Oid *oid),
00583 
00584     protectionGetByOid(DbHandle const *dbh,
00585                        Oid const *oid,
00586                        ProtectionDescription **desc),
00587 
00588     protectionListGet(DbHandle const *dbh,
00589                       Oid **oid, ProtectionDescription ***desc,
00590                       unsigned int *nprot),
00591 
00592     dbProtectionAdd(DbHandle const *dbh,
00593                     DbProtectionDescription const *desc, int nprot),
00594 
00595     dbProtectionGet(DbHandle const *dbh,
00596                     DbProtectionDescription **desc, unsigned int *nprot),
00597 
00598     objectProtectionSet(DbHandle const *dbh, Oid const *const oid,
00599                         Oid const *const protoid),
00600     objectProtectionGet(DbHandle const *dbh, Oid const *const oid,
00601                         Oid *protoid);
00602 
00603   extern int
00604   getOpenFlags(DbHandle const *dbh);
00605 
00606   extern Boolean
00607   isPhysicalOid(DbHandle const *dbh, const Oid *oid);
00608 
00609   extern Status
00610   transactionLockSet(DbHandle const *dbh, ObjectLockMode lockmode,
00611                      ObjectLockMode *olockmode);
00612 
00613   extern const char *
00614   getOPString(OP op);
00615 
00616   extern void
00617   registerEntryTrace(FILE *, const RegisterEntry *);
00618 
00619   extern void
00620   registerTrace(FILE *, const Register *);
00621 
00622   extern Status
00623   backendInterrupt(),
00624     backendInterruptReset();
00625 
00626   extern const char *
00627   statusGet(Status status);
00628 
00629   extern const char *
00630   statusGet_err(int err);
00631 
00632   extern const char *
00633   getOidString(const Oid *);
00634 
00635   enum {
00636     ReadNone   = 0,
00637     WriteNone  = 0,
00638     ReadAll    = (unsigned short)0xffff,
00639     WriteAll   = (unsigned short)0xffff
00640   };
00641 
00642   extern const void *ObjectZero, *ObjectNone;
00643   extern int dbidGet(const Oid *oid);
00644   extern void dbidSet(Oid *oid, int dbid);
00645 
00646   static const Status Success = (Status)0;
00647 
00648   static inline int protectionDescriptionSize(int n) {
00649     return sizeof(eyedbsm::ProtectionDescription) +
00650       ((n - 1) * sizeof(eyedbsm::ProtectionAtom));
00651   }
00652 
00653   // object API
00654 
00658   class Database {
00659 
00660     public :
00670     static Status dbCreate(const char *dbfile, unsigned int version,
00671                            const DbCreateDescription &dbc,
00672                            mode_t file_mask, const char *file_group);
00673     
00679     static Status dbDelete(const char *dbfile);
00680 
00687     static Status dbMove(const char *dbfile, const DbMoveDescription &dmv);
00688 
00695     static Status dbCopy(const char *dbfile, const DbCopyDescription &dcp);
00696 
00703     static Status dbInfo(const char *dbfile, DbInfoDescription &info);
00704 
00711     static Status dbRelocate(const char *dbfile, const DbRelocateDescription &rel);
00712 
00713     Database();
00714 
00723     Status open(const char *dbfile, int flags,
00724                 const OpenHints &hints, int uid);
00725 
00730     int getOpenFlags() const;
00731 
00736     unsigned int getVersion() const;
00737 
00742     const char *getDBFile() const;
00743 
00748     const OpenHints &getOpenHints() const;
00749 
00754     Status close();
00755 
00756     // transaction management
00762     Status transactionBegin(const TransactionParams &params);
00763 
00768     Status transactionCommit();
00769 
00774     Status transactionAbort();
00775 
00781     Status transactionParamsSet(const TransactionParams &params);
00782 
00788     Status transactionParamsGet(TransactionParams &params);
00789 
00796     Status transactionLockSet(ObjectLockMode lockmode,
00797                               ObjectLockMode &olockmode);
00798 
00799     // object management
00808     Status objectCreate(const void *object,
00809                         unsigned int size, short dspid, Oid &oid);
00810 
00816     Status objectDelete(const Oid &oid);
00817 
00826     Status objectWrite(int start, int length,
00827                        const void *object, const Oid &oid);
00828 
00836     Status objectWriteCache(int start,
00837                             const void *object, const Oid & oid);
00838 
00850     Status objectRead(int start, int length, void *object,
00851                       LockMode lockmode, short &pdatid, unsigned int &psize,
00852                       const Oid & oid);
00853 
00865     Status objectReadNoCopy(int start, int length,
00866                             void *object, LockMode lockmode,
00867                             short &pdatid, unsigned int &psize,
00868                             const Oid & oid);
00869 
00878     Status objectReadCache(int start, void **object,
00879                            LockMode lockmode, const Oid & oid);
00880 
00888     Status objectSizeGet(unsigned int &size, LockMode lockmode, const Oid & oid);
00889 
00897     Status objectCheckAccess(Boolean write,
00898                              const Oid & oid, Boolean &access);
00899 
00906     Status objectLocationGet(const Oid &oid, ObjectLocation &objloc);
00907 
00915     Status objectsLocationGet(const Oid * oid, ObjectLocation *objloc,
00916                               unsigned int oid_cnt);
00917 
00924     Status objectMoveDat(const Oid & oid, short datid);
00925 
00933     Status objectsMoveDat(const Oid * oid,
00934                           unsigned int oid_cnt, short datid);
00935 
00942     Status objectMoveDsp(const Oid & oid, short dspid);
00943 
00951     Status objectsMoveDsp(const Oid * oid,
00952                           unsigned int oid_cnt, short dspid);
00953 
00961     Status objectSizeModify(unsigned int size, Boolean copy,
00962                             const Oid & oid);
00963 
00971     Status objectLock(const Oid & oid, LockMode mode, LockMode &rmode);
00972 
00979     Status objectGetLock(const Oid & oid, LockMode &rmode);
00980 
00986     Status objectDownLock(const Oid & oid);
00987 
00995     Status firstOidDatGet(short datid, Oid &oid, Boolean &found);
00996 
01005     Status nextOidDatGet(short datid, const Oid & baseoid, Oid &nextoid,
01006                          Boolean &found);
01007 
01016     Status rootEntrySet(const char *key,
01017                         const void *data, unsigned int size, Boolean create);
01018 
01026     Status rootEntryGet(const char *key,
01027                         void *data, unsigned int maxsize);
01028 
01034     Status rootEntryDelete(const char * key);
01035 
01040     Status suserUnset();
01041 
01042     // datafile management
01055     Status datCreate(const char *file, const char *name,
01056                      unsigned long long maxsize, MapType mtype,
01057                      unsigned int sizeslot,
01058                      DatType type,
01059                      mode_t file_mask, const char *file_group);
01060 
01067     Status datMove(const char *datfile, const char *newdatfile);
01068 
01074     Status datDelete(const char *datfile);
01075 
01082     Status datResize(const char *datfile,
01083                      unsigned long long newmaxsize);
01084 
01091     Status datMoveObjects(const char *dat_src, const char *dat_dest);
01092                     
01100     Status datCheck(const char *datfile, short &datid, short &dspid);
01101                     
01109     Status datDefragment(const char *datfile,
01110                          mode_t file_mask, const char *file_group);
01111 
01118     Status datRename(const char *datfile, const char *name);
01119 
01126     Status datGetInfo(const char *datfile, DatafileInfo &info);
01127 
01134     Status datGetDspid(short datid, short &dspid);
01135 
01136     // dataspace management
01142     Status dspSetDefault(const char *dataspace);
01143 
01149     Status dspGetDefault(short &dspid);
01150 
01158     Status dspCreate(const char *dataspace,
01159                      const char **datfiles, unsigned int datfile_cnt);
01160 
01168     Status dspUpdate(const char *dataspace,
01169                      const char **datfiles, unsigned int datfile_cnt);
01170 
01176     Status dspDelete(const char *dataspace);
01177 
01184     Status dspRename(const char *dataspace,
01185                      const char *dataspace_new);
01186 
01195     Status dspCheck(const char *dataspace, short &dspid,
01196                     short datid[], unsigned int &ndat);
01197                     
01204     Status dspSetCurDat(const char *dataspace,
01205                         const char *datfile);
01206 
01213     Status dspGetCurDat(const char *dataspace, short &datid);
01214 
01220     Status objectNumberSet(Oid::NX maxobjs);
01221 
01222     // protection management
01229     Status protectionCreate(const ProtectionDescription &desc, Oid &oid);
01230 
01236     Status protectionDelete(const Oid & oid);
01237 
01244     Status protectionModify(const ProtectionDescription &desc, const Oid &oid);
01245 
01253     Status protectionGetByName(const char *name,
01254                                ProtectionDescription **desc,
01255                                Oid &oid);
01256 
01263     Status protectionGetByOid(const Oid &oid,
01264                               ProtectionDescription **desc);
01265 
01273     Status protectionListGet(Oid **oid, ProtectionDescription ***desc,
01274                              unsigned int &nprot);
01275 
01282     Status dbProtectionAdd(const DbProtectionDescription &desc,
01283                            unsigned int nprot);
01284 
01291     Status dbProtectionGet(DbProtectionDescription **desc,
01292                            unsigned int &nprot);
01293 
01300     Status objectProtectionSet(const Oid & oid,
01301                                const Oid & protoid);
01302 
01309     Status objectProtectionGet(const Oid & oid,
01310                                Oid *protoid);
01311 
01317     Boolean isPhysicalOid(const Oid &oid);
01318 
01324     Status registerStart(unsigned reg_mask);
01325 
01330     Status registerClear();
01331 
01336     Status registerEnd();
01337 
01343     Status registerGet(Register **preg);
01344 
01345     ~Database();
01346 
01347   private:
01348     char *dbfile;
01349     unsigned int version;
01350     OpenHints hints;
01351     DbHandle *dbh;
01352   };
01353 
01357 }
01358 
01359 #include <eyedbsm/BIdx.h>
01360 #include <eyedbsm/HIdx.h>
01361 
01362 #endif

Generated on Mon Dec 22 18:15:54 2008 for eyedb by  doxygen 1.5.3