]> git.neil.brown.name Git - lafs-utils.git/blob - lib/lafs_print_cluster.c
Print uuid out in verbose printout of cluster header.
[lafs-utils.git] / lib / lafs_print_cluster.c
1 #include <stdio.h>
2 #include <lafs/lafs.h>
3 #include <uuid/uuid.h>
4 #include "internal.h"
5
6 static char *VerifyNames[] = {"Null", "Next", "Next2", "Sum",};
7 static char *FlagNames[] = {"Checkpoint","Start","End", NULL};
8
9 void lafs_print_cluster(struct cluster_head *head, int blocksize,
10                         int groups, int verbose)
11 {
12         struct group_head *gh;
13         struct miniblock *mb;
14         struct descriptor *desc;
15         u64 start;
16         int i;
17         long offset = 0;
18         char uuidstr[37];
19
20         if (verbose) {
21                 printf("ClusterHead:\n");
22                 printf(" IdTag     : %.8s\n", head->idtag);
23                 printf(" Flags     :");
24                 if (le32_to_cpu(head->flags)==0) printf(" -none-");
25                 else for (i=0; FlagNames[i]; i++)
26                              if (le32_to_cpu(head->flags)&(1<<i))
27                                      printf(" %s", FlagNames[i]);
28                 printf("\n");
29                 uuid_unparse(head->uuid, uuidstr);
30                 printf(" UUID      : %s\n", uuidstr);
31                 printf(" Seq       : %llu\n", (unsigned long long)__le64_to_cpu(head->seq));
32                 printf(" Hlength   : %d\n", (int)__le16_to_cpu(head->Hlength));
33                 printf(" Clength   : %d\n", (int)__le16_to_cpu(head->Clength));
34                 printf(" Checksum  : %08x\n", (unsigned int)le32_to_cpu(head->checksum));
35                 printf(" Verify    : %s\n", VerifyNames[(int)__le16_to_cpu(head->verify_type)]);
36                 printf(" NEXT      : %llu\n", (unsigned long long)__le64_to_cpu(head->next_addr));
37                 printf(" THIS      : %llu\n", (unsigned long long)__le64_to_cpu(head->this_addr));
38                 printf(" PREV      : %llu\n", (unsigned long long)__le64_to_cpu(head->prev_addr));
39         } else {
40                 char *sep="";
41                 printf("Cluster %llu(", (unsigned long long)__le64_to_cpu(head->seq));
42                 for (i=0; FlagNames[i]; i++)
43                         if (le32_to_cpu(head->flags)&(1<<i)) {
44                                 printf("%s%s", sep, FlagNames[i]);
45                                 sep = ",";
46                         }
47                 printf(") %llu < %llu > %llu\n",
48                        (unsigned long long)__le64_to_cpu(head->prev_addr),
49                        (unsigned long long)__le64_to_cpu(head->this_addr),
50                        (unsigned long long)__le64_to_cpu(head->next_addr));
51         }
52         if (!groups)
53                 return;
54
55         start = __le64_to_cpu(head->this_addr);
56         offset = (__le16_to_cpu(head->Hlength)+blocksize-1)/blocksize;
57
58         gh = head->groups;
59         i = 0;
60         while ( ((char*)gh - (char*)head) < __le16_to_cpu(head->Hlength)) {
61                 int j=0;
62                 if (verbose) {
63                         printf(" Group[%d]:\n", i);
64                         printf("  Inum    : %d\n", (int)le32_to_cpu(gh->inum));
65                         printf("  FSnum   : %d\n", (int)le32_to_cpu(gh->fsnum));
66                         printf("  Flag    : %s\n", (__le16_to_cpu(gh->truncatenum_and_flag) & 0x8000) ? "old":"new");
67                         printf("  TRnum   : %d\n", (int)__le16_to_cpu(gh->truncatenum_and_flag) & 0x7fff);
68                         printf("  Size    : %d words\n", (int)__le16_to_cpu(gh->group_size_words));
69                 } else
70                         printf(" Inode: %d/%d\n", (int)le32_to_cpu(gh->fsnum),
71                                (int)le32_to_cpu(gh->inum));
72                 desc = gh->u.desc;
73                 while (((char*)desc - (char*)gh) < __le16_to_cpu(gh->group_size_words)*4) {
74                         if (__le16_to_cpu(desc->block_bytes) <= DescMiniOffset ||
75                             __le16_to_cpu(desc->block_bytes) == DescIndex ) {
76                                 char *typ;
77                                 if (__le16_to_cpu(desc->block_bytes) != DescIndex)
78                                         typ = "Data";
79                                 else
80                                         typ = "Index";
81                                 if (verbose) {
82                                         printf("  Desc[%d]:\n", j);
83                                         printf("   Block   : %u\n", (unsigned)le32_to_cpu(desc->block_num));
84                                         printf("   Count   : %u\n", __le16_to_cpu(desc->block_cnt));
85                                         printf("   Type    : %s\n", typ);
86                                         printf("   Offset  : %ld (%llu)\n", offset,
87                                                (unsigned long long)start + offset);
88                                 } else {
89                                         if (__le16_to_cpu(desc->block_cnt) == 1)
90                                                 printf("  %s  : %u  (%llu)\n", typ,
91                                                        (unsigned)le32_to_cpu(desc->block_num),
92                                                        (unsigned long long)start + offset);
93                                         else
94                                                 printf("  %s  : %u-%u  (%llu)\n", typ,
95                                                        (unsigned)le32_to_cpu(desc->block_num),
96                                                        (unsigned)le32_to_cpu(desc->block_num)
97                                                        + __le16_to_cpu(desc->block_cnt) - 1,
98                                                        (unsigned long long)start + offset);
99                                 }
100                                 offset += __le16_to_cpu(desc->block_cnt);
101                                 desc++;
102                         } else {
103                                 int len, k;
104                                 mb = (struct miniblock *)desc;
105                                 len = __le16_to_cpu(mb->length) - DescMiniOffset;
106                                 if (verbose) {
107                                         printf("  MiniBlock[%d]:\n", j);
108                                         printf("   Block   : %u\n", (unsigned)le32_to_cpu(mb->block_num));
109                                         printf("   Offset  : %u\n", __le16_to_cpu(mb->block_offset));
110                                         printf("   length  : %u\n", len);
111                                 } else
112                                         printf("  Update: %u+%u - %u bytes\n",
113                                                (unsigned)le32_to_cpu(mb->block_num),
114                                                __le16_to_cpu(mb->block_offset), len);
115                                 mb++;
116                                 if (verbose) {
117                                         printf("   Content : ");
118                                         for (k=0; k<len; k++) {
119                                                 printf(" %02x", ((unsigned char*)mb)[k]);
120                                                 if (k > 100) {
121                                                         printf(" .....");
122                                                         break;
123                                                 }
124                                         }
125                                         printf("\n");
126                                 }
127                                 mb = (struct miniblock *)(((char*)mb) + ROUND_UP(len));
128                                 desc = (struct descriptor *)mb;
129                         }
130                         j++;
131                 }
132                 gh = (struct group_head*)desc;
133                 i++;
134         }
135         if (verbose)
136                 printf(" Final Offset : %ld (next %llu)\n", offset, (unsigned long long)start+offset);
137 }