ipc: Simplify mutex_try_lock().
[dss.git] / snap.c
diff --git a/snap.c b/snap.c
index d1caf56ed442a0eed2d1f9d0a80b90262162f717..2ec195653c8ce65091b31f512010326649387bf1 100644 (file)
--- a/snap.c
+++ b/snap.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008-2010 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 #include <sys/time.h>
 
 #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.
@@ -75,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")) {
@@ -85,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;
@@ -146,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);
 }
 
@@ -233,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;
+}