// ======================================================= void CXfsPart::scanfuncBno(char *cBlockData, DWORD dwLevel, xfs_agf *agf) { xfs_alloc_block *block = (xfs_alloc_block *)cBlockData; //ablock; xfs_alloc_ptr *pp; xfs_alloc_rec *rp; DWORD i; //showDebug(10, "scanfuncBno(cBlockData, dwLevel=%lu);\n", dwLevel); if (dwLevel == 0) { //rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, 1, mp->m_alloc_mxr[0]); rp = (xfs_alloc_rec*) (cBlockData+sizeof(xfs_alloc_block)); for (i = 0; i < BeToCpu(block->bb_numrecs); i++) addToHist(BeToCpu(agf->agf_seqno), BeToCpu(rp[i].ar_startblock), BeToCpu(rp[i].ar_blockcount)); } else { //pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, 1, mp->m_alloc_mxr[1]); showDebug(1, "TREE: multilevel: dwLevel=%lu\n",dwLevel); showDebug(10, "TREE: multilevel: dwLevel=%lu\n",dwLevel); int nVal = (int)((m_header.qwBlockSize - (uint)sizeof(xfs_alloc_block)) / ((uint)sizeof(xfs_alloc_key) + (uint)sizeof(xfs_alloc_ptr))); pp = (xfs_alloc_ptr*) (cBlockData+sizeof(xfs_alloc_block)+(nVal*sizeof(xfs_alloc_key))); // /*mp->m_alloc_mxr[1]*/ showDebug(1, "offset=%lu\n",sizeof(xfs_alloc_block)+(nVal*sizeof(xfs_alloc_key))); showDebug(10, "offset=%lu\n",sizeof(xfs_alloc_block)+(nVal*sizeof(xfs_alloc_key))); for (i = 0; i < BeToCpu(block->bb_numrecs); i++) { showDebug(10, "LEVELRECUR: i=%lu, pp=%lu\n", i, (DWORD)pp[i]); scanSbtree(agf, BeToCpu(pp[i]), dwLevel); } } }
//restore history ie read history.txt to local hist buffer void restoreHistory() { int c; char temp[1000]; FILE *f1 = fopen("history.txt","r"); printf("***********restoring**********\n"); if(f1!=NULL) { int i=0; while((c=fgetc(f1))!=EOF) { temp[i]=c; i++; if(c=='\n') { //printf("%s**\n",temp); //addToHist(temp); char *token=strtok(temp," "); token=strtok(NULL,"\n"); //printf("%s***\n",token); addToHist(token); i=0; memset(&temp[0],0,sizeof(temp)); continue; } } fclose(f1); } else { printf("no file\n"); return; } }
int main() { char *args[20]; char *input = NULL; //to be filled by getcmd int cnt, bg, status; int histCount = 0; //keeps track of which history item we're on struct hist histArray[10]; //stores history items while(1) { if ((cnt = getcmd("\n>> ", args, &bg, &input)) == 0) { printf("\nPlease enter a command.\n"); continue; } printf("\n"); //if a number is entered as first argument, execute the command with that index in the history array if (isdigit(*args[0])) { if (getCmdFromHistory(args, &input, &histArray[0], histCount) == 0) continue; extractArgs(args, input, &bg); } //add the command to history addToHist(&histArray[0], &histCount, input); if (builtInCmd(args, &histArray[0], histCount) == 1) continue; //run command if issued with '&' at the end else if (bg) { backgroundExec(args, cnt, input); } else { foregroundExec(args, cnt, &histArray[0], histCount); } free(input); } }
// ======================================================= void CXfsPart::scanFreelist(xfs_agf *agf) { DWORD dwAgNo = BeToCpu(agf->agf_seqno); xfs_agfl agfl; DWORD dwBlockNo; DWORD i; if (BeToCpu(agf->agf_flcount) == 0) return; readData(&agfl, convertAgToDaddr(dwAgNo, XFS_AGFL_DADDR), sizeof(agfl)); // process list i = BeToCpu(agf->agf_flfirst); for (;;) { dwBlockNo = BeToCpu(agfl.agfl_bno[i]); addToHist(dwAgNo, dwBlockNo, 1); if (i == BeToCpu(agf->agf_fllast)) break; if (++i == XFS_AGFL_SIZE) i = 0; } }