📄 sberr.c
字号:
}/* SBE_SDTAB(tableptr, printflag, physflag) - Auxiliary for SBE_SDLIST. * Stuffs all freelist SDBLK addresses in table for dup detection. * Returns error message (0 if no errors found). */char *sbe_sdtab(pt, p, phys)register struct ptab *pt;int p, phys;{ register struct sdblk *sd; register int res; pt->pt_pflag = (p ? PTF_PRF : 0) | (phys ? PTF_SDPHYS : 0) | PTF_OVFERR; pt->pt_cnt = pt->pt_nsto = 0; /* Initialize */ /* Stick freelist in table */ for(sd = sbx_nfl; sd; sd = sd->slforw) { if(sbe_tbent(pt, sd) < 0) { if(pt->pt_xerr < 0) PRFBAD("SD freelist too long", printf("SD freelist too long (%d)\n", NPTRS)) PRFBAD("SD freelist loop", printf("SD freelist loop at %o\n", pt->pt_xerr)) } if(sd->sdflags) { PRF(printf("Bad free SD, non-zero flag:\n")) PRFBUG("Free SD flagged", sbe_psd(sd)) } } pt->pt_hidx = pt->pt_nsto; /* Set idx of 1st non-FL entry */ return(0);}/* SBE_SCHK(SDptr, tableptr) - Auxiliary for SBE_SDLIST. * If SD not already in table, verifies or prints * the complete physical or logical list it's on, and enters all * of its SDs into table (to prevent doing it again). * Returns 0 if no errors, else error string.** There is a problem when the table overflows. The tbent routine** wants to add it (wrapping around at bottom) in that case, because** that still helps detect loops. But this routine wants to reset** the table back (after scanning to head of list) and once it starts** scanning forward again it will fail, because some of the SDs are** still in the table due to the wraparound! Thus PTF_OVFERR is always** set, in order to at least give the right error message.*/char *sbe_schk(sd, pt)register struct sdblk *sd;struct ptab *pt;{ register struct sdblk *sdx; register struct smblk *sm; struct sbfile *savfile; chroff lastaddr; int p, res, savidx, phys; phys = pt->pt_pflag&PTF_SDPHYS; /* Set up physflag */ if(phys && (sd->sdfile == 0)) /* Ignore non-phys stuff if phys */ return(0); p = pt->pt_pflag&PTF_PRF; /* Set up printflag */ savidx = pt->pt_nsto; /* Remember initial extent of table */ if(sbe_tbent(pt, sd) < 0) { if(pt->pt_xerr >= 0) /* OK if already in table */ return(0); PRFBAD("Too many SDs", printf("Too many SDs for table (%d)\n", NPTRS)) } /* Now search backward for start of list */ while(sdx = (phys ? sd->sdback : sd->slback)) if(sbe_tbent(pt,sdx) >= 0) sd = sdx; else break; if(sdx) { if(pt->pt_xerr < 0) /* Table error? */ PRFBAD("Too many SDs", printf("Too many SDs for table (%d)\n",NPTRS)) PRF(printf("Backlist loop!! Dup'd node:%s\n", (pt->pt_xerr < pt->pt_hidx) ? "(on freelist!)" : "" )) PRFBUG((phys ? "Phys SD loop" : "SD loop"), sbe_psd(sdx)) } /* Reset table to flush nodes backed over */ pt->pt_cnt = pt->pt_nsto = savidx; /* SD now points to start of list. Begin stepping thru list... */ PRF(printf("---- %sList started: ", (phys ? "Phys " : ""))) if(phys) { savfile = sd->sdfile; PRF(printf(" SF: %o, fd= %d, ln= %ld\n", savfile,savfile->sffd,savfile->sflen)) if(savfile->sfptr1 != sd) PRFBUG("SFPTR1 bad", printf(" BAD!! Sfptr1 %o doesn't match SD %o!!\n", savfile->sfptr1, sd)) lastaddr = 0; } else PRF(printf("\n")) PRF(printf("%s\n", sdhdline)) for(sdx = 0; sd; (sdx = sd, sd = (phys ? sd->sdforw : sd->slforw))) { PRF(sbe_psd(sd)) /* Print it out */ if(sdx != (phys ? sd->sdback : sd->slback)) { if(phys) PRFBUG("PSD bad sdback",printf("\tBad phys backptr\n")) else PRFBUG("SD bad slback",printf("\tBad backptr\n")) } if((sd->sdflags&0377) != SD_NID) PRFBUG("Bad SD node ID", printf("\tBad node ID!\n")) if(sd->sdfile && (sd->sdlen < 0 || sd->sdaddr < 0)) PRFBUG("SD: neg len/addr", printf("\tNeg disk len/addr\n")) if(phys) goto dophys; /* Do special stuff for logical list */ if(sm = sd->sdmem) { if((sm->smflags&0377) != SM_NID) PRFBUG("SD: bad SM", printf("\nBad SMBLK ptr\n")) if((sd->sdflags&SD_MOD)==0 && sd->sdlen != sm->smuse) PRFBUG("SD != SM", printf("\tBad SMBLK? Len conflict\n")) if(sm->smlen < sm->smuse) PRFBUG("SD: SM len < use", printf("\tBad SMBLK, len < use\n")) } goto doboth; /* Skip phys stuff */ /* Do special stuff for phys list */ dophys: if(sd->sdfile != savfile) PRFBUG("SD: bad sdfile", printf("\tBad sdfile ptr! Shd be %o\n", savfile)) if(sd->sdaddr < lastaddr) PRFBUG("SD addr out of order", printf("\tBad disk addr, not in order!\n")) lastaddr = sd->sdaddr; /* Done with special phys stuff */ doboth: if(sbe_tbent(pt, sd) < 0) { if(pt->pt_xerr < 0) PRFBAD("Too many SDs", printf("Too many SDs for table (%d)\n",NPTRS)) PRFBUG("SD loop", printf("\tLOOP!! This SD already seen%s.\n", (pt->pt_xerr < pt->pt_hidx) ? " (on freelist!)" : "" )) break; } } PRF(printf("-----------\n")) return(0);}/* SBE_DSK(SFptr) - Print out disk usage list for specific file */sbe_dsk(sfp)SBFILE *sfp;{ printf("SBFILE printout not coded: %o\n",sfp);}/* SBBUF structure debugging routines */struct flgt sbflgtab[] = { SB_OVW, 'O', SB_WRIT,'W', 0,0};static char sbfhelp[] = "O-Overwrite, W-Write";/* SBE_SBVFY(SBptr) - Verify a SB-string. * Returns error message (0 if no errors found). */char *sbe_sbvfy(sbp)SBBUF *sbp;{ return(sbe_sbs(sbp,0));}/* SBE_SBS(SBptr, printflag) - Verify/Print SBSTR data stuff * Returns error message (0 if no errors found). */char *sbe_sbs(sbp,p)SBBUF *sbp;int p;{ register SBBUF *sb; register struct smblk *sm; register struct sdblk *sd; sb = sbp; PRF(printf("SBSTR %o: ",sb)) if(sb == 0) PRFBUG(0,printf("Zero pointer???\n")) /* First print out cryptic summary in case pointers bomb * out farther on. */ PRF(printf(" (io,cur,r,w,f,.,+ = %o,%o,%d,%d,%o,%lo,%lo)\n", sb->sbiop, sb->sbcur, sb->sbrleft, sb->sbwleft, sb->sbflags, sb->sbdot, sb->sboff)) PRF(printf(" sbflags %5o = %s (%s)\n", sb->sbflags, sbe_fstr(sb->sbflags,sbflgtab), sbfhelp)) if(sd = sb->sbcur) /* Okay, now try getting pointers */ sm = sd->sdmem; else sm = 0; PRF(printf(" sbcur %6o",sd)) if(sd) { PRF(printf("\n %s\n ", sdhdline)) PRF(sbe_psd(sd)) if((sd->sdflags&0377) != SD_NID) PRFBUG("SBCUR not SD?",printf(" BAD SDBLK ID!! \n")) if(sm) { PRF(printf(" %s\n ", smhdline)) PRF(sbe_smp(sm,0)) if((sm->smflags&0377) != SM_NID) PRFBUG("SBCUR has bad SM", printf(" BAD SMBLK ID!!\n")) } } PRF(printf(" sbiop %6o",sb->sbiop)) if(sb->sbiop) { if(!sm || sb->sbiop < sm->smaddr || sb->sbiop > (sm->smaddr + sm->smlen)) PRFBUG("Bad SBIOP", printf(" BAD")) } else if(sb->sbrleft > 0 || sb->sbwleft > 0) PRFBUG("Bad SBIOP/cnts", printf(" BAD")) PRF(printf("\n")) PRF(printf(" sbrleft %5o = %5d.",sb->sbrleft, sb->sbrleft)) if(sb->sbrleft && ( !sm || sb->sbwleft || (sb->sbflags&SB_WRIT) || (sb->sbrleft != (sm->smuse - (sb->sbiop - sm->smaddr))) )) PRFBUG("Bad sbrleft", printf(" BAD")) PRF(printf("\n")) PRF(printf(" sbwleft %5o = %5d.", sb->sbwleft, sb->sbwleft)) if(sb->sbwleft && ( !sm || (sb->sbflags&SB_WRIT) == 0 || (sb->sbwleft > (sm->smlen - (sb->sbiop - sm->smaddr))) )) PRFBUG("Bad sbwleft", printf(" BAD")) PRF(printf("\n")) PRF(printf(" sbdot %7lo = %7ld.", sb->sbdot, sb->sbdot)) if(sb->sbdot < 0) PRFBUG("Bad sbdot", printf(" BAD")) PRF(printf("\n sboff %7lo = %7ld.\n", sb->sboff, sb->sboff)) PRF(printf(" I/O ptr loc: %ld.\n\n", sb_tell(sb))) return(0);}/* SBE_TBENT() - Auxiliary to add and check entries to a pointer table. * Note we assume here that smblk ptrs are used, although sdblks * can also be hacked. This wins as long as the two kinds of ptrs * are basically identical (saves horrible casting problems). * Returns index # if successful (between 0 and NPTRS-1 inclusive). * Otherwise an error (-1), with relevant info in pt_xerr: * -1 if out of room and flag set making it an error * 0-n if entry already existed. */sbe_tbent(pt, sm)register struct ptab *pt;struct smblk *sm;{ register struct smblk **smt; register int i; int p; p = pt->pt_pflag&PTF_PRF; /* Set up print flag */ smt = &(pt->pt_tab[0]); if(i = pt->pt_nsto) { do { if(sm == *smt++) { pt->pt_xerr = pt->pt_nsto - i; return(-1); } } while(--i); --smt; } i = pt->pt_cnt++; if(++(pt->pt_nsto) > NPTRS) { if(pt->pt_pflag&PTF_OVFERR) { pt->pt_err = "Ptrtab overflow"; pt->pt_xerr = -1; return(-1); } pt->pt_nsto = NPTRS; i %= NPTRS; } pt->pt_tab[i] = sm; return(i);}/* SBE_FSTR(flags, flagtab) - Auxiliary to convert flag word to a string * and return pointer to it. Handy for printfs. */char *sbe_fstr(flags, fp)register int flags;register struct flgt *fp;{ static char retstr[17]; /* Max of 16 flags */ register char *cp; cp = retstr; for(; fp->flg_bit; ++fp) *cp++ = (fp->flg_bit&flags) ? fp->flg_chr : ' '; *cp = 0; return(retstr);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -