* [PATCH] xfsprogs: comment & robustify blkmap_next_off()
@ 2012-05-02 19:27 Eric Sandeen
0 siblings, 0 replies; only message in thread
From: Eric Sandeen @ 2012-05-02 19:27 UTC (permalink / raw)
To: xfs-oss
When looking at blkmap_next_off I was a little puzzled,
so I started adding comments. Hopefully this helps.
I also noticed that if you happen to pass in a "t"
beyond the last map, it'll happily go read off the
end of the array and return you something based on what
it finds, seems better to catch that & return something
obvious instead.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/repair/bmap.c b/repair/bmap.c
index c43ca7f..85d66dc 100644
--- a/repair/bmap.c
+++ b/repair/bmap.c
@@ -206,8 +206,25 @@ blkmap_last_off(
return ext->startoff + ext->blockcount;
}
-/*
- * Return the next offset in a block map.
+/**
+ * blkmap_next_off - Return next logical block offset in a block map.
+ * @blkmap: blockmap to use
+ * @o: current file logical block number
+ * @t: current extent index into blockmap (in/out)
+ *
+ * Given a logical block offset in a file, return the next mapped logical offset
+ * The map index "t" tracks the current extent number in the block map, and
+ * is updated automatically if the returned offset resides within the next
+ * mapped extent.
+ *
+ * If the blockmap contains no extents, or no more logical offsets are mapped,
+ * or the extent index exceeds the number of extents in the map,
+ * return NULLDFILOFF.
+ *
+ * If offset o is beyond extent index t, the first offset in the next extent
+ * after extent t will be returned.
+ *
+ * Intended to be called starting with offset 0, index 0, and iterated.
*/
xfs_dfiloff_t
blkmap_next_off(
@@ -223,10 +240,12 @@ blkmap_next_off(
*t = 0;
return blkmap->exts[0].startoff;
}
+ if (*t >= blkmap->nexts)
+ return NULLDFILOFF;
ext = blkmap->exts + *t;
if (o < ext->startoff + ext->blockcount - 1)
return o + 1;
- if (*t >= blkmap->nexts - 1)
+ if (*t == blkmap->nexts - 1)
return NULLDFILOFF;
(*t)++;
return ext[1].startoff;
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-05-02 19:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-02 19:27 [PATCH] xfsprogs: comment & robustify blkmap_next_off() Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox