1: #if !defined(lint) && defined(DOSCCS)
   2: static  char *sccsid = "@(#)dumpitime.c	1.2 (2.11BSD GTE) 12/6/94";
   3: #endif
   4: 
   5: #include "dump.h"
   6: 
   7: char *prdate(d)
   8:     time_t d;
   9: {
  10:     register char *p;
  11: 
  12:     if(d == 0)
  13:         return("the epoch");
  14:     p = ctime(&d);
  15:     p[24] = 0;
  16:     return(p);
  17: }
  18: 
  19: inititimes()
  20: {
  21:             FILE    *df;
  22:     register    int i;
  23:     register    struct  itime   *itwalk;
  24: 
  25:     if (idates_in)
  26:         return;
  27:     if ( (df = fopen(increm, "r")) == NULL){
  28:         nidates = 0;
  29:         ithead = 0;
  30:     } else {
  31:         do{
  32:             itwalk=(struct itime *)calloc(1,sizeof (struct itime));
  33:             if (getrecord(df, &(itwalk->it_value)) < 0)
  34:                 break;
  35:             nidates++;
  36:             itwalk->it_next = ithead;
  37:             ithead = itwalk;
  38:         } while (1);
  39:         fclose(df);
  40:     }
  41: 
  42:     idates_in = 1;
  43:     /*
  44: 	 *	arrayify the list, leaving enough room for the additional
  45: 	 *	record that we may have to add to the idate structure
  46: 	 */
  47:     idatev = (struct idates **)calloc((unsigned)(nidates + 1), sizeof (struct idates *));
  48:     for (i = nidates-1, itwalk = ithead; i >= 0; i--, itwalk = itwalk->it_next)
  49:         idatev[i] = &itwalk->it_value;
  50: }
  51: 
  52: getitime()
  53: {
  54:     register    struct  idates  *ip;
  55:     register    int i;
  56:             char    *fname;
  57: 
  58:     fname = disk;
  59: #ifdef FDEBUG
  60:     msg("Looking for name %s in increm = %s for delta = %c\n",
  61:         fname, increm, incno);
  62: #endif
  63:     spcl.c_ddate = 0;
  64:     lastlevel = '0';
  65: 
  66:     inititimes();
  67:     /*
  68: 	 *	Go find the entry with the same name for a lower increment
  69: 	 *	and older date
  70: 	 */
  71:     ITITERATE(i, ip){
  72:         if(strncmp(fname, ip->id_name,
  73:                 sizeof (ip->id_name)) != 0)
  74:             continue;
  75:         if (ip->id_incno >= incno)
  76:             continue;
  77:         if (ip->id_ddate <= spcl.c_ddate)
  78:             continue;
  79:         spcl.c_ddate = ip->id_ddate;
  80:         lastlevel = ip->id_incno;
  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: time_t  unctime();
 161: 
 162: int makeidate(ip, buf)
 163:     struct  idates  *ip;
 164:     char    *buf;
 165: {
 166:     char    un_buf[128];
 167: 
 168:     sscanf(buf, DUMPINFMT, ip->id_name, &ip->id_incno, un_buf);
 169:     ip->id_ddate = unctime(un_buf);
 170:     if (ip->id_ddate < 0)
 171:         return(-1);
 172:     return(0);
 173: }
 174: 
 175: est(ip)
 176:     struct dinode *ip;
 177: {
 178:     long s;
 179: 
 180:     esize++;
 181:     s = (ip->di_size + DEV_BSIZE-1) / DEV_BSIZE;
 182:     esize += s;
 183:     if(s > NADDR-3) {
 184:         /*
 185: 		 *	This code is only appproximate.
 186: 		 *	it totally estimates low on doubly and triply indirect
 187: 		 *	files.
 188: 		 */
 189:         s -= NADDR-3;
 190:         s = ((s + DEV_BSIZE/sizeof(daddr_t))-1) / (DEV_BSIZE/sizeof(daddr_t));
 191:         esize += s;
 192:     }
 193: }
 194: 
 195: bmapest(map)
 196: short *map;
 197: {
 198:     register i, n;
 199: 
 200:     n = -1;
 201:     for(i=0; i<MSIZ; i++)
 202:         if(map[i])
 203:             n = i;
 204:     if(n < 0)
 205:         return;
 206:     esize++;
 207:     esize += (n + (DEV_BSIZE/sizeof(short))-1) / (DEV_BSIZE/sizeof(short));
 208: }

Defined functions

bmapest defined in line 195; used 2 times
est defined in line 175; used 2 times
getitime defined in line 52; used 1 times
getrecord defined in line 139; used 1 times
  • in line 33
inititimes defined in line 19; used 2 times
makeidate defined in line 162; used 1 times
prdate defined in line 7; used 5 times
putitime defined in line 84; used 1 times
recout defined in line 127; used 1 times

Defined variables

recno defined in line 138; used 3 times
sccsid defined in line 2; never used
Last modified: 1994-12-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3231
Valid CSS Valid XHTML 1.0 Strict