+/*
+ * An edge snapshot is either the oldest one or the newest one.
+ *
+ * We need to find either of them occasionally: The create code
+ * needs to know the newest snapshot because that is the one
+ * used as the link destination dir. The pruning code needs to
+ * find the oldest one in case disk space becomes low.
+ */
+struct edge_snapshot_data {
+ int64_t now;
+ struct snapshot snap;
+};
+
+__printf_2_3 void dss_log(int ll, const char* fmt,...)
+{
+ va_list argp;
+ FILE *outfd;
+ struct tm *tm;
+ time_t t1;
+ char str[255] = "";
+
+ if (ll < conf.loglevel_arg)
+ return;
+ outfd = logfile? logfile : stderr;
+ time(&t1);
+ tm = localtime(&t1);
+ strftime(str, sizeof(str), "%b %d %H:%M:%S", tm);
+ fprintf(outfd, "%s ", str);
+ if (conf.loglevel_arg <= INFO)
+ fprintf(outfd, "%i: ", ll);
+ va_start(argp, fmt);
+ vfprintf(outfd, fmt, argp);
+ va_end(argp);
+}
+
+/**
+ * Print a message either to stdout or to the log file.
+ */
+__printf_1_2 void dss_msg(const char* fmt,...)
+{
+ FILE *outfd = conf.daemon_given? logfile : stdout;
+ va_list argp;
+ va_start(argp, fmt);
+ vfprintf(outfd, fmt, argp);
+ va_end(argp);
+}
+
+/**
+ * Return the desired number of snapshots of an interval.
+ */
+unsigned num_snapshots(int interval)
+{
+ unsigned n;
+
+ assert(interval >= 0);
+
+ if (interval >= conf.num_intervals_arg)
+ return 0;
+ n = conf.num_intervals_arg - interval - 1;
+ return 1 << n;
+}
+
+/* return: Whether dirname is a snapshot directory (0: no, 1: yes) */