+/* Bounds the ring geometry read from a file's header to the real file's limits
+ * so that truncated files can stil be used in best effort mode.
+ */
+static void bound_ring_geometry(size_t mapsize, size_t ofs,
+ size_t *size, size_t *head, size_t *tail)
+{
+ size_t avail = (ofs < mapsize) ? mapsize - ofs : 0;
+
+ if (*size > avail) {
+ fprintf(stderr, "Note: ring size (%llu) larger than the %llu bytes left in the "
+ "file, bounding it to the file (truncated dump?).\n",
+ (unsigned long long)*size, (unsigned long long)avail);
+ *size = avail;
+ }
+
+ if (*size && *head >= *size) {
+ fprintf(stderr, "Note: head (%llu) outside of the %llu bytes storage, "
+ "restarting from the beginning.\n",
+ (unsigned long long)*head, (unsigned long long)*size);
+ *head = 0;
+ }
+
+ if (tail && *tail > *size) {
+ fprintf(stderr, "Note: tail (%llu) outside of the %llu bytes storage, "
+ "bounding it to the end of the storage.\n",
+ (unsigned long long)*tail, (unsigned long long)*size);
+ *tail = *size;
+ }
+}
+