void initdumptimes(void) { FILE *df; if ((df = fopen(dumpdates, "r")) == NULL) { if (errno != ENOENT) { msg("WARNING: cannot read %s: %s\n", dumpdates, strerror(errno)); return; } /* * Dumpdates does not exist, make an empty one. */ msg("WARNING: no file `%s', making an empty one\n", dumpdates); if ((df = fopen(dumpdates, "w")) == NULL) { msg("WARNING: cannot create %s: %s\n", dumpdates, strerror(errno)); return; } (void) fclose(df); if ((df = fopen(dumpdates, "r")) == NULL) { quit("cannot read %s even after creating it: %s\n", dumpdates, strerror(errno)); /* NOTREACHED */ } } (void) flock(fileno(df), LOCK_SH); readdumptimes(df); (void) fclose(df); }
void putdumptime(void) { FILE *df; struct dumpdates *dtwalk; int fd, i; char *fname; time_t t; if(uflag == 0) return; if ((df = fopen(dumpdates, "r+")) == NULL) quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno)); fd = fileno(df); (void) flock(fd, LOCK_EX); fname = disk; free((char *)ddatev); ddatev = 0; nddates = 0; dthead = 0; ddates_in = 0; readdumptimes(df); if (fseek(df, 0L, SEEK_SET) < 0) quit("fseek: %s\n", strerror(errno)); spcl.c_ddate = 0; ITITERATE(i, dtwalk) { if (strncmp(fname, dtwalk->dd_name, sizeof(dtwalk->dd_name)) != 0) continue; if (dtwalk->dd_level != level) continue; goto found; } /* * construct the new upper bound; * Enough room has been allocated. */ dtwalk = ddatev[nddates] = (struct dumpdates *)calloc(1, sizeof(struct dumpdates)); nddates += 1; found: (void) strlcpy(dtwalk->dd_name, fname, sizeof(dtwalk->dd_name)); dtwalk->dd_level = level; dtwalk->dd_ddate = (time_t)spcl.c_date; ITITERATE(i, dtwalk) { dumprecout(df, dtwalk); }