Commit 7db51896 authored by lw's avatar lw

*** empty log message ***

parent 1fd73444
......@@ -936,3 +936,53 @@ dbs_Body(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, pwr_eBix bix)
return p;
}
dbs_sObject *
dbs_NextHead(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op)
{
dbs_sObject *eop = (dbs_sObject*)(ep->base + ep->sect[dbs_eSect_object].offset + ep->sect[dbs_eSect_object].size);
if (op == NULL)
op = (dbs_sObject*)(ep->base + ep->sect[dbs_eSect_object].offset);
else
op = (dbs_sObject*)((char *)op + dbs_dAlign(sizeof(dbs_sObject)));
if (op >= eop)
return NULL;
return op;
}
dbs_sBody *
dbs_NextRbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp)
{
dbs_sBody *ebp = (dbs_sBody*)(ep->base + ep->sect[dbs_eSect_rbody].offset + ep->sect[dbs_eSect_rbody].size);
if (bp == NULL)
bp = (dbs_sBody*)(ep->base + ep->sect[dbs_eSect_rbody].offset);
else
bp = (dbs_sBody*)((char *)bp + dbs_dAlign(sizeof(dbs_sBody)) + dbs_dAlign(bp->size));
if (bp >= ebp)
return NULL;
return bp;
}
dbs_sBody *
dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp)
{
dbs_sBody *ebp = (dbs_sBody*)(ep->base + ep->sect[dbs_eSect_dbody].offset + ep->sect[dbs_eSect_dbody].size);
if (bp == NULL)
bp = (dbs_sBody*)(ep->base + ep->sect[dbs_eSect_dbody].offset);
else
bp = (dbs_sBody*)((char *)bp + dbs_dAlign(sizeof(dbs_sBody)) + dbs_dAlign(bp->size));
if (bp >= ebp)
return NULL;
return bp;
}
......@@ -428,6 +428,10 @@ struct dbs_sObject {
pwr_tObjName normname; /**< normalized object name. */
pwr_tTime time; /**< time of last change in object header */
pwr_tOid soid; /**< object identifier of server object. */
pwr_tOid boid; /**< object identifier of sibling object before this object. */
pwr_tOid aoid; /**< object identifier of sibling object after this object. */
pwr_tOid foid; /**< object identifier of first child object. */
pwr_tOid loid; /**< object identifier of last child object. */
dbs_mFlags flags;
dbs_sBodyRef rbody; /**< runtime body */
......@@ -608,6 +612,9 @@ struct dbs_sScObject {
%dbs_sObject *dbs_Object(pwr_tStatus *sts, const dbs_sEnv *ep);
%void dbs_ObjectToName(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, char *name);
%void *dbs_Body(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op, pwr_eBix bix);
%dbs_sObject *dbs_NextHead(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sBody *dbs_NextRbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
%dbs_sBody *dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
%
%
%#ifdef __cplusplus
......
......@@ -59,7 +59,7 @@ int dcli_get_defaultfilename(
int dcli_replace_env( char *str, char *newstr);
#endif
char *dcli_fgetname( FILE *fp, char *name, char *def_name);
int dcli_translate_filename( char *out, char *in);
int dcli_translate_filename( char *out, const char *in);
/* Functions in module co_dcli_dir */
......
......@@ -259,10 +259,11 @@ char *dcli_fgetname( FILE *fp, char *name, char *def_name)
*
**************************************************************************/
int dcli_translate_filename( char *out, char *in)
int dcli_translate_filename( char *out, const char *in)
{
char out_name[200];
char *s, *t;
const char *s;
char *t;
int i;
int state;
......
......@@ -29,7 +29,7 @@ wb_dbs::wb_dbs(wb_vrep *v) :
{
pwr_tStatus sts;
memset(m_name, 0, sizeof(m_name));
memset(m_fileName, 0, sizeof(m_fileName));
memset(&m_volume, 0, sizeof(m_volume));
memset(m_sect, 0, sizeof(m_sect));
......@@ -44,8 +44,8 @@ wb_dbs::wb_dbs(wb_vrep *v) :
//@todo strcpy(m_volume.className, m_ohp->chp->db.name.data);
sprintf(m_name, dbs_cNameVolume, dbs_cDirectory, m_v->name());
dcli_translate_filename(m_name, m_name);
sprintf(m_fileName, dbs_cNameVolume, dbs_cDirectory, m_v->name());
dcli_translate_filename(m_fileName, m_fileName);
m_oid_th = tree_CreateTable(&sts, sizeof(pwr_tOid), offsetof(sOentry, o.oid),
sizeof(sOentry), 1000, tree_Comp_oid);
......@@ -73,6 +73,11 @@ wb_dbs::~wb_dbs()
tree_DeleteTable(&sts, m_class_th);
}
void
wb_dbs::setFileName(const char *name)
{
dcli_translate_filename(m_fileName, name);
}
static int
comp_dbs_name(tree_sTable *tp, tree_sNode *x, tree_sNode *y)
......@@ -221,6 +226,10 @@ wb_dbs::importHead(pwr_tOid oid, pwr_tCid cid, pwr_tOid poid, pwr_tOid aoid, pwr
oep->o.oid = oid;
oep->o.cid = cid;
oep->o.poid = poid;
oep->o.boid = boid;
oep->o.aoid = aoid;
oep->o.foid = foid;
oep->o.loid = loid;
strcpy(oep->o.name, name);
strcpy(oep->o.normname, normname);
......@@ -264,9 +273,9 @@ wb_dbs::closeFile(pwr_tBoolean doDelete)
if (m_fp != NULL)
fclose(m_fp);
if (doDelete && *m_name != '\0') {
if (remove(m_name) == 0)
printf("-- Deleted file: %s\n", m_name);
if (doDelete && *m_fileName != '\0') {
if (remove(m_fileName) == 0)
printf("-- Deleted file: %s\n", m_fileName);
}
return LDH__SUCCESS;
......@@ -385,17 +394,17 @@ wb_dbs::openFile()
{
char *fn;
cdh_ToLower(m_name, m_name);
cdh_ToLower(m_fileName, m_fileName);
m_fp = fopen(m_name, "w+b");
m_fp = fopen(m_fileName, "w+b");
if (m_fp == NULL) {
printf("** Cannot open file: %s\n", m_name);
printf("** Cannot open file: %s\n", m_fileName);
perror(" Reason");
return LDH__FILEOPEN;
}
fn = dcli_fgetname(m_fp, m_name, m_name);
fn = dcli_fgetname(m_fp, m_fileName, m_fileName);
if (fn != NULL)
printf("-- Opened load file: %s\n", m_name);
printf("-- Opened load file: %s\n", m_fileName);
return LDH__SUCCESS;
}
......@@ -408,8 +417,8 @@ wb_dbs::writeSectFile()
PDR pdrs;
co_GetOwnFormat(&fp->format);
fp->cookie = 550715339;
//file.size;
fp->cookie = dbs_cMagicCookie;
fp->size = 0;
fp->offset = dbs_dAlign(sizeof(*fp));
fp->formatVersion = dbs_cVersionFormat;
fp->version = dbs_cVersionFile;
......@@ -418,8 +427,8 @@ wb_dbs::writeSectFile()
fp->time = m_volume.time;
fp->fileType = dbs_eFile_volume;
//file.userName;
//file.comment;
strcpy(fp->userName, "");
strcpy(fp->comment, "");
printf("format.......: %d\n", fp->format.m);
printf("cookie.......: %d\n", fp->cookie);
printf("size.........: %d\n", fp->size);
......@@ -450,6 +459,7 @@ wb_dbs::writeSectDirectory()
m_sect[dbs_eSect_volref].version = dbs_cVersionVolRef;
m_sect[dbs_eSect_oid].version = dbs_cVersionOid;
m_sect[dbs_eSect_object].version = dbs_cVersionObject;
m_sect[dbs_eSect_scobject].version = dbs_cVersionScObject;
m_sect[dbs_eSect_rbody].version = dbs_cVersionRbody;
m_sect[dbs_eSect_name].version = dbs_cVersionName;
m_sect[dbs_eSect_class].version = dbs_cVersionClass;
......@@ -460,6 +470,7 @@ wb_dbs::writeSectDirectory()
m_sect[dbs_eSect_volref].type = dbs_eSect_volref;
m_sect[dbs_eSect_oid].type = dbs_eSect_oid;
m_sect[dbs_eSect_object].type = dbs_eSect_object;
m_sect[dbs_eSect_scobject].type = dbs_eSect_scobject;
m_sect[dbs_eSect_rbody].type = dbs_eSect_rbody;
m_sect[dbs_eSect_name].type = dbs_eSect_name;
m_sect[dbs_eSect_class].type = dbs_eSect_class;
......@@ -521,7 +532,8 @@ wb_dbs::writeSectVolume()
pwr_tStatus
wb_dbs::writeSectVolref()
{
dbs_sVolRef volref;
char v[dbs_dAlign(sizeof(dbs_sVolRef))];
dbs_sVolRef *vp = (dbs_sVolRef*)v;
cdh_uTid cid;
sCentry *cep;
pwr_tStatus sts;
......@@ -529,10 +541,10 @@ wb_dbs::writeSectVolref()
if (fseek(m_fp, m_sect[dbs_eSect_volref].offset, SEEK_SET) != 0)
return LDH__FILEPOS;
memset(&volref, 0, sizeof(volref));
memset(v, 0, sizeof(v));
cid.pwr = pwr_cNCid;
cep = (sCentry*)tree_FindSuccessor(&sts, m_class_th, &cid.pwr);
cep = (sCentry*)tree_FindSuccessor(&sts, m_class_th, &cid.pwr);
while (cep) {
cdh_uVid vid;
......@@ -542,17 +554,18 @@ wb_dbs::writeSectVolref()
vid.v.vid_1 = cid.c.vid_1;
if (vid.pwr != m_volume.vid) {
printf("volref: %d.%d.%d.%d\n", vid.v.vid_0, vid.v.vid_1, vid.v.vid_2, vid.v.vid_3);
volref.vid = vid.pwr;
//volref.name = ?;
volref.cid = pwr_eClass_ClassVolume;
//vp->time = ?;
//volref.size = ?;
//volref.offset = ?;
if (fwrite(&volref, sizeof(volref), 1, m_fp) < 1)
printf("volref: %d.%d.%d.%d\n", vid.v.vid_3, vid.v.vid_2, vid.v.vid_1, vid.v.vid_0);
vp->vid = vid.pwr;
strcpy(vp->name, "not_yet_known");
vp->cid = 0;
vp->time.tv_sec = 0;
vp->time.tv_nsec = 0;
vp->size = 0;
vp->offset = 0;
if (fwrite(v, sizeof(v), 1, m_fp) < 1)
return LDH__FILEWRITE;
m_sect[dbs_eSect_volref].size += sizeof(volref);
m_sect[dbs_eSect_volref].size += sizeof(v);
}
vid.pwr++;
cid.pwr = pwr_cNCid;
......
......@@ -68,7 +68,7 @@ public:
};
FILE *m_fp; /**< file pointer */
char m_name[100]; /**< name of load file */
char m_fileName[512]; /**< name of load file */
// wb_object *m_o; /* Volume object header. */
wb_vrep *m_v;
dbs_sVolume m_volume;
......@@ -102,7 +102,8 @@ public:
bool operator==(wb_dbs&);
// void buildFile();
void setFileName(const char *name);
void buildSectName();
void buildSectOid();
void buildSectClass();
......
......@@ -2,6 +2,7 @@
#include "wb_orepdbs.h"
#include "wb_erep.h"
#include "wb_merep.h"
#include "wb_import.h"
void wb_vrepdbs::unref()
{
......@@ -432,3 +433,51 @@ void wb_vrepdbs::objectName(wb_orep *o, char *str)
dbs_ObjectToName(&sts, dbsenv(), ((wb_orepdbs *)o)->o(), str);
}
bool wb_vrepdbs::exportVolume(wb_import &i)
{
return i.importVolume(*this);
}
bool wb_vrepdbs::exportHead(wb_import &i)
{
dbs_sObject *op = 0;
pwr_tStatus sts;
while ((op = dbs_NextHead(&sts, dbsenv(), op))) {
i.importHead(op->oid, op->cid, op->poid, op->aoid, op->boid, op->foid, op->loid, op->name, op->normname,
op->time, op->rbody.time, op->dbody.time, op->rbody.size, op->dbody.size);
}
return true;
}
bool wb_vrepdbs::exportRbody(wb_import &i)
{
dbs_sBody *bp = 0;
pwr_tStatus sts;
while ((bp = dbs_NextRbody(&sts, dbsenv(), bp))) {
i.importRbody(bp->oid, bp->size, (void*)(bp + 1));
}
return true;
}
bool wb_vrepdbs::exportDbody(wb_import &i)
{
dbs_sBody *bp = 0;
pwr_tStatus sts;
while ((bp = dbs_NextDbody(&sts, dbsenv(), bp))) {
i.importDbody(bp->oid, bp->size, (void*)(bp + 1));
}
return true;
}
bool wb_vrepdbs::exportMeta(wb_import &i)
{
return false;
}
......@@ -128,11 +128,11 @@ public:
virtual bool isMeta() const { return (cid() == pwr_eClass_ClassVolume);}
virtual bool exportVolume(wb_import &e) { return false;}
virtual bool exportHead(wb_import &e) { return false;}
virtual bool exportRbody(wb_import &e) { return false;}
virtual bool exportDbody(wb_import &e) { return false;}
virtual bool exportMeta(wb_import &e) { return false;}
virtual bool exportVolume(wb_import &e);
virtual bool exportHead(wb_import &e);
virtual bool exportRbody(wb_import &e);
virtual bool exportDbody(wb_import &e);
virtual bool exportMeta(wb_import &e);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment