]> git.neil.brown.name Git - lafs-utils.git/blob - lib/lafs_incorporate.c
Remove lots of white-space errors
[lafs-utils.git] / lib / lafs_incorporate.c
1
2 /*
3  * Given an index block with some ->uninc blocks, add all the addresses
4  * of those blocks into the index info.
5  *
6  * FIXME
7  * For now we only support Indirect index in the inode as that is enough
8  * for mkfs
9  */
10
11 #include <lafs/lafs.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include "internal.h"
15
16 #define encode16(p,n) ({ *(p++) = (n)&255; *(p++) = ((n)>>8) & 255; })
17 #define encode32(p,n) ({ encode16(p,n); encode16(p, ((n)>>16)); })
18 #define encode48(p,n) ({ encode32(p,n); encode16(p, ((n)>>32)); })
19
20 void lafs_incorporate(struct lafs_iblk *ib)
21 {
22         struct lafs *fs = ib->b.ino->fs;
23         unsigned char *ip;
24         int max_addr;
25
26         if (ib->uninc == NULL)
27                 return;
28
29         if (ib->depth != 1)
30                 abort();
31
32
33         ip = (void*)(ib->b.ino->dblock->b.data + ib->b.ino->metadata_size);
34         if (*(u16*)ip != __cpu_to_le16(IBLK_INDIRECT))
35                 abort();
36         ip += 2;
37
38         max_addr = fs->blocksize - ib->b.ino->metadata_size;
39         max_addr -= 2; /* for type field */
40         max_addr /= 6; /* 6 bytes per address */
41
42         while (ib->uninc) {
43                 struct lafs_blk *b = ib->uninc;
44                 int addr;
45                 unsigned char *ip2 = ip;
46
47                 ib->uninc = b->chain;
48                 b->chain = NULL;
49
50                 addr = b->fileaddr - ib->b.fileaddr;
51                 if (addr >= max_addr)
52                         abort();
53                 ip2 += addr * 6;
54                 encode48(ip2, b->physaddr);
55         }
56         trace(1, "incorporate %d/%lld\n", ib->b.ino->dblock->b.ino->inum,
57                (long long)ib->b.ino->dblock->b.fileaddr);
58         lafs_dirty_blk(&ib->b);
59 }