-enum snapshot_status_flags {
- SS_COMPLETE = 1,
- SS_BEING_DELETED = 2,
-};
-
-struct snapshot {
- char *name;
- int64_t creation_time;
- int64_t completion_time;
- enum snapshot_status_flags flags;
- unsigned interval;
-};
-
-int is_snapshot(const char *dirname, int64_t now, struct snapshot *s)
-{
- int i, ret;
- char *dash, *dot, *tmp;
- int64_t num;
-
- assert(dirname);
- dash = strchr(dirname, '-');
- if (!dash || !dash[1] || dash == dirname)
- return 0;
- for (i = 0; dirname[i] != '-'; i++)
- if (!isdigit(dirname[i]))
- return 0;
- tmp = dss_strdup(dirname);
- tmp[i] = '\0';
- ret = dss_atoi64(tmp, &num);
- free(tmp);
- if (ret < 0) {
- free(dss_error_txt);
- return 0;
- }
- assert(num >= 0);
- 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)
- / conf.unit_interval_arg / 24 / 3600);
- if (!strcmp(dash + 1, "incomplete")) {
- s->completion_time = -1;
- s->flags = 0; /* neither complete, nor being deleted */
- goto success;
- }
- if (!strcmp(dash + 1, "incomplete.being_deleted")) {
- s->completion_time = -1;
- s->flags = SS_BEING_DELETED; /* mot cpmplete, being deleted */
- goto success;
- }
- tmp = dash + 1;
- dot = strchr(tmp, '.');
- if (!dot || !dot[1] || dot == tmp)
- return 0;
- for (i = 0; tmp[i] != '.'; i++)
- if (!isdigit(tmp[i]))
- return 0;
- tmp = dss_strdup(dash + 1);
- tmp[i] = '\0';
- ret = dss_atoi64(tmp, &num);
- free(tmp);
- if (ret < 0) {
- free(dss_error_txt);
- return 0;
- }
- if (num > now)
- return 0;
- s->completion_time = num;
- s->flags = SS_COMPLETE;
- if (strcmp(dot + 1, "being_deleted"))
- s->flags |= SS_BEING_DELETED;
-success:
- s->name = dss_strdup(dirname);
- return 1;
-}
-
-int64_t get_current_time(void)
-{
- time_t now;
- time(&now);
- DSS_DEBUG_LOG("now: %lli\n", (long long) now);
- return (int64_t)now;
-}
-
-char *incomplete_name(int64_t start)
-{
- return make_message("%lli-incomplete", (long long)start);
-}
-
-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);
-}
-
-int complete_name(int64_t start, int64_t end, char **result)