]> git.neil.brown.name Git - LaFS.git/commitdiff
remove_from_index: various fixes.
authorNeilBrown <neilb@suse.de>
Tue, 8 Jun 2010 08:22:39 +0000 (18:22 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 10 Jun 2010 06:05:09 +0000 (16:05 +1000)
1/ Skip offset for InoIdx
2/ when moving address down, clear the space at the end
3/ stop when we find the last address.

Signed-off-by: NeilBrown <neilb@suse.de>
modify.c

index d248e3e0c054c609b8ca8303dde7f144eb720e3e..97aa2d7221134cf8000aeadb6fc884c558715d62 100644 (file)
--- a/modify.c
+++ b/modify.c
@@ -1583,25 +1583,37 @@ static u32 remove_from_index(struct indexblock *ib, u32 addr)
        u64 phys;
        u32 a;
        int found = 0;
+       int type;
 
-       p = buf+2;
+       p = buf;
+       if (test_bit(B_InoIdx, &ib->b.flags)) {
+               int offset = LAFSI(ib->b.inode)->metadata_size;
+               len -= offset;
+               p += offset;
+       }
+       type = decode16(p);
        len -= 2;
+       LAFS_BUG(type != IBLK_INDEX, &ib->b);
        while (len > 10) {
                phys = decode48(p);
                a = decode32(p);
                len -= 10;
+               if (phys == 0)
+                       break;
                if (found) {
                        p -= 20;
                        encode48(p, phys);
                        encode32(p, a);
-                       p += 10;
+                       encode48(p, 0ULL);
+                       encode32(p, 0UL);
                        if (rv == 0)
                                rv = a;
                } else if (a == addr)
                        found = 1;
                else
-                       BUG_ON(a > addr);
+                       LAFS_BUG(a > addr, &ib->b);
        }
+       LAFS_BUG(!found, &ib->b);
        unmap_iblock(ib, buf);
        lafs_dirty_iblock(ib);
        return rv;