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