X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=snap.c;h=2ec195653c8ce65091b31f512010326649387bf1;hp=c47e688f19f928d80f5c5e6a06d2cfaa92745bbf;hb=5235e61583d358c177955c1da642e7c49e527acc;hpb=952745a3f7cc03b9581454d1c32f735b8ad16f93 diff --git a/snap.c b/snap.c index c47e688..2ec1956 100644 --- a/snap.c +++ b/snap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -11,13 +11,14 @@ #include #include #include +#include #include "gcc-compat.h" -#include "error.h" +#include "err.h" #include "snap.h" -#include "string.h" -#include "time.h" -#include "fd.h" +#include "str.h" +#include "tv.h" +#include "file.h" /** * Wrapper for isdigit. @@ -74,7 +75,6 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, if (num > now) return 0; s->creation_time = num; - //DSS_DEBUG_LOG("%s start time: %lli\n", dirname, (long long)s->creation_time); s->interval = (long long) ((now - s->creation_time) / unit_interval / 24 / 3600); if (!strcmp(dash + 1, "incomplete")) { @@ -84,7 +84,7 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, } if (!strcmp(dash + 1, "incomplete.being_deleted")) { s->completion_time = -1; - s->flags = SS_BEING_DELETED; /* mot cpmplete, being deleted */ + s->flags = SS_BEING_DELETED; /* not complete, being deleted */ goto success; } tmp = dash + 1; @@ -100,7 +100,7 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, free(tmp); if (ret < 0) return 0; - if (num > now) + if (num > now || num < s->creation_time) return 0; s->completion_time = num; s->flags = SS_COMPLETE; @@ -145,8 +145,8 @@ static int add_snapshot(const char *dirname, void *private) static int compare_snapshots(const void *a, const void *b) { - struct snapshot *s1 = *(struct snapshot **)a; - struct snapshot *s2 = *(struct snapshot **)b; + struct snapshot *s1 = *(struct snapshot * const *)a; + struct snapshot *s2 = *(struct snapshot * const *)b; return NUM_COMPARE(s2->creation_time, s1->creation_time); } @@ -154,11 +154,10 @@ static int compare_snapshots(const void *a, const void *b) void get_snapshot_list(struct snapshot_list *sl, int unit_interval, int num_intervals) { - struct add_snapshot_data asd = { - .unit_interval = unit_interval, - .num_intervals = num_intervals, - .sl = sl - }; + struct add_snapshot_data asd; + asd.unit_interval = unit_interval; + asd.num_intervals = num_intervals; + asd.sl = sl; sl->now = get_current_time(); sl->num_snapshots = 0; sl->array_size = 0; @@ -187,17 +186,15 @@ void free_snapshot_list(struct snapshot_list *sl) __malloc char *incomplete_name(int64_t start) { - return make_message("%lli-incomplete", (long long)start); + return make_message("%" PRId64 "-incomplete", start); } __malloc char *being_deleted_name(struct snapshot *s) { if (s->flags & SS_COMPLETE) - return make_message("%lli-%lli.being_deleted", - (long long)s->creation_time, - (long long)s->completion_time); - return make_message("%lli-incomplete.being_deleted", - (long long)s->creation_time); + return make_message("%" PRId64 "-%" PRId64 ".being_deleted", + s->creation_time, s->completion_time); + return make_message("%" PRId64 "-incomplete.being_deleted", s->creation_time); } int complete_name(int64_t start, int64_t end, char **result) @@ -215,7 +212,7 @@ int complete_name(int64_t start, int64_t end, char **result) return -E_STRFTIME; if (!strftime(end_str, sizeof(end_str), "%a_%b_%d_%Y_%H_%M_%S", &end_tm)) return -E_STRFTIME; - *result = make_message("%lli-%lli.%s-%s", (long long) start, (long long) end, + *result = make_message("%" PRId64 "-%" PRId64 ".%s-%s", start, end, start_str, end_str); return 1; } @@ -235,3 +232,13 @@ __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl) return name; } +int num_complete_snapshots(struct snapshot_list *sl) +{ + struct snapshot *s; + int i, ret = 0; + + FOR_EACH_SNAPSHOT(s, i, sl) + if (s->flags & SS_COMPLETE) + ret++; + return ret; +}