📄 infofile.c
字号:
if(ch != '\0') { if(sscanf((s - 1), "%jd", &time_t_tmp) != 1) { amfree(line); break; } onehistory.secs = (time_t)time_t_tmp; skip_integer(s, ch); } info->history[nb_history++] = onehistory; } amfree(line); while ((line = agets(infof)) != NULL) { if (line[0] != '\0') break; amfree(line); } if (line == NULL) return -1; amfree(line); return rc;}static intwrite_txinfofile( FILE * infof, info_t * info){ int i; stats_t *sp; perf_t *pp; int level; g_fprintf(infof, _("version: %d\n"), 0); g_fprintf(infof, _("command: %u\n"), info->command); pp = &info->full; g_fprintf(infof, "full-rate:"); for(i=0; i<AVG_COUNT; i++) if(pp->rate[i] >= 0.0) g_fprintf(infof, " %lf", pp->rate[i]); g_fprintf(infof, "\n"); g_fprintf(infof, "full-comp:"); for(i=0; i<AVG_COUNT; i++) if(pp->comp[i] >= 0.0) g_fprintf(infof, " %lf", pp->comp[i]); g_fprintf(infof, "\n"); pp = &info->incr; g_fprintf(infof, "incr-rate:"); for(i=0; i<AVG_COUNT; i++) if(pp->rate[i] >= 0.0) g_fprintf(infof, " %lf", pp->rate[i]); g_fprintf(infof, "\n"); g_fprintf(infof, "incr-comp:"); for(i=0; i<AVG_COUNT; i++) if(pp->comp[i] >= 0.0) g_fprintf(infof, " %lf", pp->comp[i]); g_fprintf(infof, "\n"); for(level=0; level<DUMP_LEVELS; level++) { sp = &info->inf[level]; if(sp->date < (time_t)0 && sp->label[0] == '\0') continue; g_fprintf(infof, "stats: %d %lld %lld %jd %lld", level, (long long)sp->size, (long long)sp->csize, (intmax_t)sp->secs, (long long)sp->date); if(sp->label[0] != '\0') g_fprintf(infof, " %lld %s", (long long)sp->filenum, sp->label); g_fprintf(infof, "\n"); } g_fprintf(infof, _("last_level: %d %d\n"), info->last_level, info->consecutive_runs); for(i=0;info->history[i].level > -1;i++) { g_fprintf(infof, _("history: %d %lld %lld %jd %jd\n"), info->history[i].level, (long long)info->history[i].size, (long long)info->history[i].csize, (intmax_t)info->history[i].date, (intmax_t)info->history[i].secs); } g_fprintf(infof, "//\n"); return 0;}static intdelete_txinfofile( char * host, char * disk){ char *fn = NULL, *fn_new = NULL; int rc; char *myhost; char *mydisk; myhost = sanitise_filename(host); mydisk = sanitise_filename(disk); fn = vstralloc(infodir, "/", myhost, "/", mydisk, "/info", NULL); fn_new = stralloc2(fn, ".new"); amfree(myhost); amfree(mydisk); unlink(fn_new); amfree(fn_new); rc = rmpdir(fn, infodir); amfree(fn); return rc;}intopen_infofile( char * filename){ assert(infodir == (char *)0); infodir = stralloc(filename); return 0; /* success! */}voidclose_infofile(void){ assert(infodir != (char *)0); amfree(infodir);}/* Convert a dump level to a GMT based time stamp */char *get_dumpdate( info_t * info, int lev){ static char stamp[20]; /* YYYY:MM:DD:hh:mm:ss */ int l; time_t this, last; struct tm *t; last = EPOCH; for(l = 0; l < lev; l++) { this = info->inf[l].date; if (this > last) last = this; } t = gmtime(&last); g_snprintf(stamp, SIZEOF(stamp), "%d:%d:%d:%d:%d:%d", t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); return stamp;}/* * Weighted average */doubleperf_average( double * a, /* array of items to average */ double d) /* default value */{ double sum; /* running total */ int n; /* number of items in sum */ int w; /* weight */ int i; /* counter */ sum = 0.0; n = 0; for(i = 0; i < AVG_COUNT; i++) { if(a[i] >= 0.0) { w = AVG_COUNT - i; sum += a[i] * w; n += w; } } if(n == 0) return d; return sum / n;}static voidzero_info( info_t *info){ int i; memset(info, '\0', SIZEOF(info_t)); for(i = 0; i < AVG_COUNT; i++) { info->full.comp[i] = info->incr.comp[i] = -1.0; info->full.rate[i] = info->incr.rate[i] = -1.0; } for(i = 0; i < DUMP_LEVELS; i++) { info->inf[i].date = (time_t)-1; } info->last_level = -1; info->consecutive_runs = -1; for(i=0;i<=NB_HISTORY;i++) { info->history[i].level = -2; info->history[i].size = (off_t)0; info->history[i].csize = (off_t)0; info->history[i].date = 0UL; } return;}intget_info( char * hostname, char * diskname, info_t * info){ int rc; (void) zero_info(info); { FILE *infof; infof = open_txinfofile(hostname, diskname, "r"); if(infof == NULL) { rc = -1; /* record not found */ } else { rc = read_txinfofile(infof, info); close_txinfofile(infof); } } return rc;}intput_info( char * hostname, char * diskname, info_t * info){ FILE *infof; int rc; infof = open_txinfofile(hostname, diskname, "w"); if(infof == NULL) return -1; rc = write_txinfofile(infof, info); rc = rc || close_txinfofile(infof); return rc;}intdel_info( char * hostname, char * diskname){ return delete_txinfofile(hostname, diskname);}#ifdef TESTvoid dump_rec(info_t *info);voiddump_rec( info_t * info){ int i; stats_t *sp; g_printf(_("command word: %d\n"), info->command); g_printf(_("full dump rate (K/s) %5.1lf, %5.1lf, %5.1lf\n"), info->full.rate[0],info->full.rate[1],info->full.rate[2]); g_printf(_("full comp rate %5.1lf, %5.1lf, %5.1lf\n"), info->full.comp[0]*100,info->full.comp[1]*100,info->full.comp[2]*100); g_printf(_("incr dump rate (K/s) %5.1lf, %5.1lf, %5.1lf\n"), info->incr.rate[0],info->incr.rate[1],info->incr.rate[2]); g_printf(_("incr comp rate %5.1lf, %5.1lf, %5.1lf\n"), info->incr.comp[0]*100,info->incr.comp[1]*100,info->incr.comp[2]*100); for(i = 0; i < DUMP_LEVELS; i++) { sp = &info->inf[i]; if( sp->size != -1) { g_printf(_("lev %d date %ld tape %s filenum %lld size %ld csize %ld secs %ld\n"), i, (long)sp->date, sp->label, sp->filenum, sp->size, sp->csize, sp->secs); } } putchar('\n'); g_printf(_("last_level: %d %d\n"), info->last_level, info->consecutive_runs);}void dump_db( char *host, char *disk);voiddump_db( char * host, char * disk){ info_t info; int rc; if((rc = get_info(host, disk, &info)) == 0) { dump_rec(&info); } else { g_printf(_("cannot fetch information for %s:%s rc=%d\n"), host, disk, rc); }}intmain( int argc, char ** argv){ int i; /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); safe_fd(-1, 0); set_pname("infofile"); dbopen(DBG_SUBDIR_SERVER); for(i = 1; i < argc; ++i) { if(i+1 >= argc) { g_fprintf(stderr,_("usage: %s host disk [host disk ...]\n"),argv[0]); return 1; } open_infofile("curinfo"); dump_db(argv[i], argv[i+1]); i++; close_infofile(); } return 0;}#endif /* TEST */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -