diff --git a/newrpl/backup.c b/newrpl/backup.c index 9608888..9756965 100644 --- a/newrpl/backup.c +++ b/newrpl/backup.c @@ -13,7 +13,7 @@ // CONVERT A POINTER INTO A ROMPTR ID // IF IT FAILS, RETURNS 0 -WORD rplConvertToRomptrID(WORDPTR ptr) +UBINT64 rplConvertToRomptrID(WORDPTR ptr) { BINT libnum=MAXLIBNUMBER; BINT SavedOpcode; @@ -30,9 +30,9 @@ WORD rplConvertToRomptrID(WORDPTR ptr) (*han)(); - if(RetNum==OK_CONTINUE) return ObjectID; + if(RetNum==OK_CONTINUE) return ((UBINT64)ObjectID) | (((UBINT64)ObjectIDHash)<<32); } - --libnum; + libnum=rplGetNextLib(libnum); } CurOpcode=SavedOpcode; @@ -45,7 +45,7 @@ WORD rplConvertToRomptrID(WORDPTR ptr) // RETURNS 0 IF NOT A VALID ID // OR NOT RECOGNIZED BY ITS LIBRARIES -WORDPTR rplConvertIDToPTR(WORD romptrid) +WORDPTR rplConvertIDToPTR(UBINT64 romptrid) { if(!ISROMPTRID(romptrid)) return 0; @@ -61,6 +61,7 @@ WORDPTR rplConvertIDToPTR(WORD romptrid) if(!han) return 0; RetNum=ERR_INVALID; ObjectID=romptrid; + ObjectIDHash=romptrid>>32; (*han)(); @@ -137,23 +138,23 @@ BINT rplBackup(int (*writefunc)(unsigned int,void *),void *OpaqueArgument) sections[k].nitems=DirsTop-Directories; sections[k].offwords=offset; - offset+=sections[k].nitems; + offset+=sections[k].nitems*2; ++k; // SYSTEM POINTERS sections[k].start=(WORDPTR)GC_PTRUpdate; - sections[k].nitems=MAX_GC_PTRUPDATE; + sections[k].nitems=(MAX_GC_PTRUPDATE); sections[k].offwords=offset; - offset+=sections[k].nitems; + offset+=sections[k].nitems*2; ++k; // STACK sections[k].start=(WORDPTR)DStk; - sections[k].nitems=DSTop-DStk; + sections[k].nitems=(DSTop-DStk); sections[k].offwords=offset; - offset+=sections[k].nitems; + offset+=sections[k].nitems*2; ++k; // FILL ALL OTHER SECTIONS @@ -177,6 +178,13 @@ BINT rplBackup(int (*writefunc)(unsigned int,void *),void *OpaqueArgument) ++writeoff; } + // WRITE ALL 10 SECTIONS nitems + for(k=0;k<10;++k) { + if(!writefunc(sections[k].nitems,OpaqueArgument)) return 0; + ++writeoff; + } + + // TODO: WRITE OTHER SYSTEM VARIABLES HERE // FILL THE HEADER SECTION @@ -210,11 +218,11 @@ BINT rplBackup(int (*writefunc)(unsigned int,void *),void *OpaqueArgument) // VALID POINTER INTO TEMPOB, CONVERT INTO FILE OFFSET if(!writefunc( (BINT)(ptr-TempOb)+ sections[1].offwords,OpaqueArgument)) return 0; } else { - // IF THE OBJECT IS NOT IN TEMPOB IS IN ROM + // IF THE OBJECT IS NOT IN TEMPOB, IS IN ROM // CONVERT TO ROMPTR ID - WORD id=rplConvertToRomptrID(ptr); + UBINT64 id=rplConvertToRomptrID(ptr); if(!id) { // INVALID POINTER! NEED TO FIX THE MEMORY BEFORE DOING BACKUP @@ -222,10 +230,16 @@ BINT rplBackup(int (*writefunc)(unsigned int,void *),void *OpaqueArgument) return 0; } if(!writefunc(id,OpaqueArgument)) return 0; + if(ROMPTRID_OFF(id)==31) { + ++writeoff; + if(!writefunc((id>>32),OpaqueArgument)) return 0; + } } ++writeoff; } + while(writeoff>32),OpaqueArgument)) return 0; + } } ++writeoff; } + while(writeoff>32),OpaqueArgument)) return 0; + } + } ++writeoff; } + while(writeoff0) sections[k-1].nitems=sections[k].offwords-sections[k-1].offwords; } - + // READ nitems, RESTORE FROM OFFSETS IF NOTE PRESENT (BACKWARDS COMPATIBLE WITH OLD BACKUP FORMAT) + for(k=0;k<10;++k) + { + sections[k].nitems=readfunc(OpaqueArgument); + ++offset; + if((k>0) && (sections[k-1].nitems==0)) sections[k-1].nitems=sections[k].offwords-sections[k-1].offwords; + } // RESET RPL ENVIRONMENT // ERASE ALL RPL MEMORY IN PREPARATION FOR RESTORE @@ -375,7 +408,7 @@ BINT rplRestoreBackup(BINT includestack,WORD (*readfunc)(void *),void *OpaqueArg // RESIZE ALL SECTIONS TO THE REQUESTED SIZE if(sections[0].nitems+TEMPBLOCKSLACK>1024) growTempBlocks(sections[0].nitems+TEMPBLOCKSLACK); if(sections[1].nitems+sections[2].nitems>1024) growTempOb(sections[1].nitems+sections[2].nitems); - if(sections[3].nitems+DIRSLACK>1024) growDirs(sections[3].nitems+DIRSLACK); + if((sections[3].nitems)+DIRSLACK>1024) growDirs(sections[3].nitems+DIRSLACK); if(includestack) { if(sections[5].nitems+DSTKSLACK>1024) growDirs(sections[5].nitems+DSTKSLACK); } @@ -384,7 +417,7 @@ BINT rplRestoreBackup(BINT includestack,WORD (*readfunc)(void *),void *OpaqueArg // SKIP TO THE PROPER FILE OFFSET - while(offset!=1024) { readfunc(OpaqueArgument); ++offset; } + while(offset<1024) { readfunc(OpaqueArgument); ++offset; } // HERE'S THE START OF TEMPBLOCKS for(k=0;k=table[idx]) && (ptr30) { + ObjectID=MKROMPTRID(libnum,idx,31); // MARK OFFSET=31 TO INDICATE OFFSET EXCEEDS THE OFFSET + ObjectIDHash=libComputeHash(ptr); + } + else { + ObjectID=MKROMPTRID(libnum,idx,offset); + ObjectIDHash=0; + } + RetNum=OK_CONTINUE; return; } @@ -148,7 +156,7 @@ void libGetRomptrID(BINT libnum,WORDPTR *table,WORDPTR ptr) return; } -void libGetPTRFromID(WORDPTR *table,WORD id) +void libGetPTRFromID(WORDPTR *table,WORD id,WORD hash) { BINT idx=0; while(table[idx]) ++idx; @@ -156,7 +164,33 @@ void libGetPTRFromID(WORDPTR *table,WORD id) RetNum=ERR_NOTMINE; return; } - ObjectPTR=table[ROMPTRID_IDX(id)]+ROMPTRID_OFF(id); + if(ROMPTRID_OFF(id)<31) ObjectPTR=table[ROMPTRID_IDX(id)]+ROMPTRID_OFF(id); + else { + // SCAN THE OBJECT TO FIND A MATCHING HASH + WORDPTR scan=table[ROMPTRID_IDX(id)],ptr; + WORDPTR end=rplSkipOb(scan); + BINT len; + WORD exhash; + scan+=31; // MINIMUM OFFSET FOR A SEARCH + while(scan