|
|
1.1 ! root 1: static char *sccsid = "@(#)dumpitime.c 1.1 (Berkeley) 10/13/80"; ! 2: #include "dump.h" ! 3: ! 4: char *prdate(d) ! 5: time_t d; ! 6: { ! 7: char *p; ! 8: ! 9: if(d == 0) ! 10: return("the epoch"); ! 11: p = ctime(&d); ! 12: p[24] = 0; ! 13: return(p); ! 14: } ! 15: ! 16: struct idates **idatev = 0; ! 17: int nidates = 0; ! 18: int idates_in = 0; ! 19: struct itime *ithead = 0; ! 20: ! 21: inititimes() ! 22: { ! 23: FILE *df; ! 24: register int i; ! 25: register struct itime *itwalk; ! 26: ! 27: if (idates_in) ! 28: return; ! 29: if ( (df = fopen(increm, "r")) == NULL){ ! 30: nidates = 0; ! 31: ithead = 0; ! 32: } else { ! 33: do{ ! 34: itwalk=(struct itime *)calloc(1,sizeof (struct itime)); ! 35: if (getrecord(df, &(itwalk->it_value)) < 0) ! 36: break; ! 37: nidates++; ! 38: itwalk->it_next = ithead; ! 39: ithead = itwalk; ! 40: } while (1); ! 41: fclose(df); ! 42: } ! 43: ! 44: idates_in = 1; ! 45: /* ! 46: * arrayify the list, leaving enough room for the additional ! 47: * record that we may have to add to the idate structure ! 48: */ ! 49: idatev = (struct idates **)calloc(nidates + 1,sizeof (struct idates *)); ! 50: for (i = nidates-1, itwalk = ithead; i >= 0; i--, itwalk = itwalk->it_next) ! 51: idatev[i] = &itwalk->it_value; ! 52: } ! 53: ! 54: getitime() ! 55: { ! 56: register struct idates *ip; ! 57: register int i; ! 58: char *fname; ! 59: ! 60: fname = disk; ! 61: #ifdef FDEBUG ! 62: msg("Looking for name %s in increm = %s for delta = %c\n", ! 63: fname, increm, incno); ! 64: #endif ! 65: spcl.c_ddate = 0; ! 66: ! 67: inititimes(); ! 68: /* ! 69: * Go find the entry with the same name for a lower increment ! 70: * and older date ! 71: */ ! 72: ITITERATE(i, ip){ ! 73: if(strncmp(fname, ip->id_name, ! 74: sizeof (ip->id_name)) != 0) ! 75: continue; ! 76: if (ip->id_incno >= incno) ! 77: continue; ! 78: if (ip->id_ddate <= spcl.c_ddate) ! 79: continue; ! 80: spcl.c_ddate = ip->id_ddate; ! 81: } ! 82: } ! 83: ! 84: putitime() ! 85: { ! 86: FILE *df; ! 87: register struct idates *itwalk; ! 88: register int i; ! 89: char *fname; ! 90: ! 91: if(uflag == 0) ! 92: return; ! 93: fname = disk; ! 94: ! 95: spcl.c_ddate = 0; ! 96: ITITERATE(i, itwalk){ ! 97: if (strncmp(fname, itwalk->id_name, ! 98: sizeof (itwalk->id_name)) != 0) ! 99: continue; ! 100: if (itwalk->id_incno != incno) ! 101: continue; ! 102: goto found; ! 103: } ! 104: /* ! 105: * construct the new upper bound; ! 106: * Enough room has been allocated. ! 107: */ ! 108: itwalk = idatev[nidates] = ! 109: (struct idates *)calloc(1, sizeof(struct idates)); ! 110: nidates += 1; ! 111: found: ! 112: strncpy(itwalk->id_name, fname, sizeof (itwalk->id_name)); ! 113: itwalk->id_incno = incno; ! 114: itwalk->id_ddate = spcl.c_date; ! 115: ! 116: if ( (df = fopen(increm, "w")) == NULL){ ! 117: msg("Cannot open %s\n", increm); ! 118: dumpabort(); ! 119: } ! 120: ITITERATE(i, itwalk){ ! 121: recout(df, itwalk); ! 122: } ! 123: fclose(df); ! 124: msg("level %c dump on %s\n", incno, prdate(spcl.c_date)); ! 125: } ! 126: ! 127: recout(file, what) ! 128: FILE *file; ! 129: struct idates *what; ! 130: { ! 131: fprintf(file, DUMPOUTFMT, ! 132: what->id_name, ! 133: what->id_incno, ! 134: ctime(&(what->id_ddate)) ! 135: ); ! 136: } ! 137: ! 138: int recno; ! 139: int getrecord(df, idatep) ! 140: FILE *df; ! 141: struct idates *idatep; ! 142: { ! 143: char buf[BUFSIZ]; ! 144: ! 145: recno = 0; ! 146: if ( (fgets(buf, BUFSIZ, df)) != buf) ! 147: return(-1); ! 148: recno++; ! 149: if (makeidate(idatep, buf) < 0) ! 150: msg("Unknown intermediate format in %s, line %d\n", ! 151: NINCREM, recno); ! 152: ! 153: #ifdef FDEBUG ! 154: msg("getrecord: %s %c %s\n", ! 155: idatep->id_name, idatep->id_incno, prdate(idatep->id_ddate)); ! 156: #endif ! 157: return(0); ! 158: } ! 159: ! 160: /* ! 161: * Convert from old format to new format ! 162: * Convert from /etc/ddate to /etc/dumpdates format ! 163: */ ! 164: o_nconvert() ! 165: { ! 166: FILE *oldfile; ! 167: FILE *newfile; ! 168: struct idates idate; ! 169: struct idates idatecopy; ! 170: ! 171: if( (newfile = fopen(NINCREM, "w")) == NULL){ ! 172: msg("%s: Can not open %s to update.\n", processname, NINCREM); ! 173: Exit(X_ABORT); ! 174: } ! 175: if ( (oldfile = fopen(OINCREM, "r")) != NULL){ ! 176: while(!feof(oldfile)){ ! 177: if (fread(&idate, sizeof(idate), 1, oldfile) != 1) ! 178: break; ! 179: /* ! 180: * The old format ddate did not have ! 181: * the full special path name on it; ! 182: * we add the prefix /dev/ to the ! 183: * special name, although this may not be ! 184: * always the right thing to do. ! 185: */ ! 186: idatecopy = idate; ! 187: strcpy(idatecopy.id_name, "/dev/"); ! 188: strncat(idatecopy.id_name, idate.id_name, ! 189: sizeof(idate.id_name) - sizeof ("/dev/")); ! 190: recout(newfile, &idatecopy); ! 191: } ! 192: } ! 193: fclose(oldfile); ! 194: fclose(newfile); ! 195: } ! 196: ! 197: time_t unctime(); ! 198: ! 199: int makeidate(ip, buf) ! 200: struct idates *ip; ! 201: char *buf; ! 202: { ! 203: char un_buf[128]; ! 204: ! 205: sscanf(buf, DUMPINFMT, ip->id_name, &ip->id_incno, un_buf); ! 206: ip->id_ddate = unctime(un_buf); ! 207: if (ip->id_ddate < 0) ! 208: return(-1); ! 209: return(0); ! 210: } ! 211: ! 212: est(ip) ! 213: struct dinode *ip; ! 214: { ! 215: long s; ! 216: ! 217: esize++; ! 218: s = (ip->di_size + BSIZE-1) / BSIZE; ! 219: esize += s; ! 220: if(s > NADDR-3) { ! 221: /* ! 222: * This code is only appproximate. ! 223: * it totally estimates low on doubly and triply indirect ! 224: * files. ! 225: */ ! 226: s -= NADDR-3; ! 227: s = (s + (BSIZE/sizeof(daddr_t))-1) / (BSIZE/sizeof(daddr_t)); ! 228: esize += s; ! 229: } ! 230: } ! 231: ! 232: bmapest(map) ! 233: short *map; ! 234: { ! 235: register i, n; ! 236: ! 237: n = -1; ! 238: for(i=0; i<MSIZ; i++) ! 239: if(map[i]) ! 240: n = i; ! 241: if(n < 0) ! 242: return; ! 243: esize++; ! 244: esize += (n + (BSIZE/sizeof(short))-1) / (BSIZE/sizeof(short)); ! 245: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.