1 static char *sccsid = "@(#)itime.c 1.7 (Berkeley) 12/02/82"; 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 /* 213 * This is an estimation of the number of TP_BSIZE blocks in the file. 214 * It assumes that there are no unallocated blocks; hence 215 * the estimate may be high 216 */ 217 est(ip) 218 struct dinode *ip; 219 { 220 long s; 221 222 esize++; 223 /* calc number of TP_BSIZE blocks */ 224 s = howmany(ip->di_size, TP_BSIZE); 225 if (ip->di_size > sblock->fs_bsize * NDADDR) { 226 /* calc number of indirect blocks on the dump tape */ 227 s += howmany(s - NDADDR * sblock->fs_bsize / TP_BSIZE, 228 TP_NINDIR); 229 } 230 esize += s; 231 } 232 233 bmapest(map) 234 char *map; 235 { 236 register i, n; 237 238 n = -1; 239 for (i = 0; i < msiz; i++) 240 if(map[i]) 241 n = i; 242 if(n < 0) 243 return; 244 n++; 245 esize++; 246 esize += howmany(n * sizeof map[0], TP_BSIZE); 247 } 248