]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/log_misc.c
xfs: remove inode log format typedef
[thirdparty/xfsprogs-dev.git] / logprint / log_misc.c
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #include "libxfs.h"
19 #include "libxlog.h"
20
21 #include "logprint.h"
22
23 #define CLEARED_BLKS (-5)
24 #define ZEROED_LOG (-4)
25 #define FULL_READ (-3)
26 #define PARTIAL_READ (-2)
27 #define BAD_HEADER (-1)
28 #define NO_ERROR (0)
29
30 static int logBBsize;
31
32 typedef struct xlog_split_item {
33 struct xlog_split_item *si_next;
34 struct xlog_split_item *si_prev;
35 xlog_tid_t si_xtid;
36 int si_skip;
37 } xlog_split_item_t;
38
39 xlog_split_item_t *split_list = NULL;
40
41 void
42 print_xlog_op_line(void)
43 {
44 printf("--------------------------------------"
45 "--------------------------------------\n");
46 } /* print_xlog_op_line */
47
48 void
49 print_xlog_xhdr_line(void)
50 {
51 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
52 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
53 } /* print_xlog_xhdr_line */
54
55 void
56 print_xlog_record_line(void)
57 {
58 printf("======================================"
59 "======================================\n");
60 } /* print_xlog_record_line */
61
62 void
63 print_stars(void)
64 {
65 printf("***********************************"
66 "***********************************\n");
67 } /* print_stars */
68
69 /*
70 * Given a pointer to a data segment, print out the data as if it were
71 * a log operation header.
72 */
73 void
74 xlog_print_op_header(xlog_op_header_t *op_head,
75 int i,
76 char **ptr)
77 {
78 xlog_op_header_t hbuf;
79
80 /*
81 * memmove because on 64/n32, partial reads can cause the op_head
82 * pointer to come in pointing to an odd-numbered byte
83 */
84 memmove(&hbuf, op_head, sizeof(xlog_op_header_t));
85 op_head = &hbuf;
86 *ptr += sizeof(xlog_op_header_t);
87 printf(_("Oper (%d): tid: %x len: %d clientid: %s "), i,
88 be32_to_cpu(op_head->oh_tid),
89 be32_to_cpu(op_head->oh_len),
90 (op_head->oh_clientid == XFS_TRANSACTION ? "TRANS" :
91 (op_head->oh_clientid == XFS_LOG ? "LOG" : "ERROR")));
92 printf(_("flags: "));
93 if (op_head->oh_flags) {
94 if (op_head->oh_flags & XLOG_START_TRANS)
95 printf("START ");
96 if (op_head->oh_flags & XLOG_COMMIT_TRANS)
97 printf("COMMIT ");
98 if (op_head->oh_flags & XLOG_WAS_CONT_TRANS)
99 printf("WAS_CONT ");
100 if (op_head->oh_flags & XLOG_UNMOUNT_TRANS)
101 printf("UNMOUNT ");
102 if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
103 printf("CONTINUE ");
104 if (op_head->oh_flags & XLOG_END_TRANS)
105 printf("END ");
106 } else {
107 printf(_("none"));
108 }
109 printf("\n");
110 } /* xlog_print_op_header */
111
112
113 void
114 xlog_print_add_to_trans(xlog_tid_t tid,
115 int skip)
116 {
117 xlog_split_item_t *item;
118
119 item = (xlog_split_item_t *)calloc(sizeof(xlog_split_item_t), 1);
120 item->si_xtid = tid;
121 item->si_skip = skip;
122 item->si_next = split_list;
123 item->si_prev = NULL;
124 if (split_list)
125 split_list->si_prev = item;
126 split_list = item;
127 } /* xlog_print_add_to_trans */
128
129
130 int
131 xlog_print_find_tid(xlog_tid_t tid, uint was_cont)
132 {
133 xlog_split_item_t *listp = split_list;
134
135 if (!split_list) {
136 if (was_cont != 0) /* Not first time we have used this tid */
137 return 1;
138 else
139 return 0;
140 }
141 while (listp) {
142 if (listp->si_xtid == tid)
143 break;
144 listp = listp->si_next;
145 }
146 if (!listp) {
147 return 0;
148 }
149 if (--listp->si_skip == 0) {
150 if (listp == split_list) { /* delete at head */
151 split_list = listp->si_next;
152 if (split_list)
153 split_list->si_prev = NULL;
154 } else {
155 if (listp->si_next)
156 listp->si_next->si_prev = listp->si_prev;
157 listp->si_prev->si_next = listp->si_next;
158 }
159 free(listp);
160 }
161 return 1;
162 } /* xlog_print_find_tid */
163
164 int
165 xlog_print_trans_header(char **ptr, int len)
166 {
167 xfs_trans_header_t *h;
168 char *cptr = *ptr;
169 uint32_t magic;
170 char *magic_c = (char *)&magic;
171
172 *ptr += len;
173
174 magic = *(uint32_t *)cptr; /* XXX be32_to_cpu soon */
175
176 if (len >= 4) {
177 #if __BYTE_ORDER == __LITTLE_ENDIAN
178 printf("%c%c%c%c:",
179 magic_c[3], magic_c[2], magic_c[1], magic_c[0]);
180 #else
181 printf("%c%c%c%c:",
182 magic_c[0], magic_c[1], magic_c[2], magic_c[3]);
183 #endif
184 }
185 if (len != sizeof(xfs_trans_header_t)) {
186 printf(_(" Not enough data to decode further\n"));
187 return 1;
188 }
189 h = (xfs_trans_header_t *)cptr;
190 printf(_(" tid: %x num_items: %d\n"),
191 h->th_tid, h->th_num_items);
192 return 0;
193 } /* xlog_print_trans_header */
194
195
196 int
197 xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
198 {
199 xfs_buf_log_format_t *f;
200 xlog_op_header_t *head = NULL;
201 int num, skip;
202 int super_block = 0;
203 int bucket, col, buckets;
204 int64_t blkno;
205 xfs_buf_log_format_t lbuf;
206 int size, blen, map_size, struct_size;
207 __be64 x, y;
208 unsigned short flags;
209
210 /*
211 * memmove to ensure 8-byte alignment for the long longs in
212 * buf_log_format_t structure
213 */
214 memmove(&lbuf, *ptr, MIN(sizeof(xfs_buf_log_format_t), len));
215 f = &lbuf;
216 *ptr += len;
217
218 ASSERT(f->blf_type == XFS_LI_BUF);
219 printf("BUF: ");
220 blkno = f->blf_blkno;
221 size = f->blf_size;
222 blen = f->blf_len;
223 map_size = f->blf_map_size;
224 flags = f->blf_flags;
225
226 /*
227 * size of the format header is dependent on the size of the bitmap, not
228 * the size of the in-memory structure. Hence the slightly obtuse
229 * calculation.
230 */
231 struct_size = offsetof(struct xfs_buf_log_format, blf_map_size) + map_size;
232
233 if (len >= struct_size) {
234 ASSERT((len - sizeof(struct_size)) % sizeof(int) == 0);
235 printf(_("#regs: %d start blkno: %lld (0x%llx) len: %d bmap size: %d flags: 0x%x\n"),
236 size, (long long)blkno, (unsigned long long)blkno, blen, map_size, flags);
237 if (blkno == 0)
238 super_block = 1;
239 } else {
240 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
241 printf(_("#regs: %d Not printing rest of data\n"), f->blf_size);
242 return size;
243 }
244 num = size-1;
245
246 /* Check if all regions in this log item were in the given LR ptr */
247 if (*i+num > num_ops-1) {
248 skip = num - (num_ops-1-*i);
249 num = num_ops-1-*i;
250 } else {
251 skip = 0;
252 }
253 while (num-- > 0) {
254 (*i)++;
255 head = (xlog_op_header_t *)*ptr;
256 xlog_print_op_header(head, *i, ptr);
257 if (super_block) {
258 printf(_("SUPER BLOCK Buffer: "));
259 if (be32_to_cpu(head->oh_len) < 4*8) {
260 printf(_("Out of space\n"));
261 } else {
262 printf("\n");
263 /*
264 * memmove because *ptr may not be 8-byte aligned
265 */
266 memmove(&x, *ptr, sizeof(__be64));
267 memmove(&y, *ptr+8, sizeof(__be64));
268 printf(_("icount: %llu ifree: %llu "),
269 (unsigned long long) be64_to_cpu(x),
270 (unsigned long long) be64_to_cpu(y));
271 memmove(&x, *ptr+16, sizeof(__be64));
272 memmove(&y, *ptr+24, sizeof(__be64));
273 printf(_("fdblks: %llu frext: %llu\n"),
274 (unsigned long long) be64_to_cpu(x),
275 (unsigned long long) be64_to_cpu(y));
276 }
277 super_block = 0;
278 } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
279 struct xfs_agi *agi, agi_s;
280
281 /* memmove because *ptr may not be 8-byte aligned */
282 agi = &agi_s;
283 memmove(agi, *ptr, sizeof(struct xfs_agi));
284 printf(_("AGI Buffer: XAGI "));
285 /*
286 * v4 filesystems only contain the fields before the uuid.
287 * Even v5 filesystems don't log any field beneath it. That
288 * means that the size that is logged is almost always going to
289 * be smaller than the structure itself. Hence we need to make
290 * sure that the buffer contains all the data we want to print
291 * rather than just check against the structure size.
292 */
293 if (be32_to_cpu(head->oh_len) < offsetof(xfs_agi_t, agi_uuid) -
294 XFS_AGI_UNLINKED_BUCKETS*sizeof(xfs_agino_t)) {
295 printf(_("out of space\n"));
296 } else {
297 printf("\n");
298 printf(_("ver: %d "),
299 be32_to_cpu(agi->agi_versionnum));
300 printf(_("seq#: %d len: %d cnt: %d root: %d\n"),
301 be32_to_cpu(agi->agi_seqno),
302 be32_to_cpu(agi->agi_length),
303 be32_to_cpu(agi->agi_count),
304 be32_to_cpu(agi->agi_root));
305 printf(_("level: %d free#: 0x%x newino: 0x%x\n"),
306 be32_to_cpu(agi->agi_level),
307 be32_to_cpu(agi->agi_freecount),
308 be32_to_cpu(agi->agi_newino));
309 if (be32_to_cpu(head->oh_len) == 128) {
310 buckets = 17;
311 } else if (be32_to_cpu(head->oh_len) == 256) {
312 buckets = 32 + 17;
313 } else {
314 if (head->oh_flags & XLOG_CONTINUE_TRANS) {
315 printf(_("AGI unlinked data skipped "));
316 printf(_("(CONTINUE set, no space)\n"));
317 continue;
318 }
319 buckets = XFS_AGI_UNLINKED_BUCKETS;
320 }
321 for (bucket = 0; bucket < buckets;) {
322 printf(_("bucket[%d - %d]: "), bucket, bucket+3);
323 for (col = 0; col < 4; col++, bucket++) {
324 if (bucket < buckets) {
325 printf("0x%x ",
326 be32_to_cpu(agi->agi_unlinked[bucket]));
327 }
328 }
329 printf("\n");
330 }
331 }
332 } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGF_MAGIC) {
333 struct xfs_agf *agf, agf_s;
334
335 /* memmove because *ptr may not be 8-byte aligned */
336 agf = &agf_s;
337 memmove(agf, *ptr, sizeof(struct xfs_agf));
338 printf(_("AGF Buffer: XAGF "));
339 /*
340 * v4 filesystems only contain the fields before the uuid.
341 * Even v5 filesystems don't log any field beneath it. That
342 * means that the size that is logged is almost always going to
343 * be smaller than the structure itself. Hence we need to make
344 * sure that the buffer contains all the data we want to print
345 * rather than just check against the structure size.
346 */
347 if (be32_to_cpu(head->oh_len) < offsetof(xfs_agf_t, agf_uuid)) {
348 printf(_("Out of space\n"));
349 } else {
350 printf("\n");
351 printf(_("ver: %d seq#: %d len: %d \n"),
352 be32_to_cpu(agf->agf_versionnum),
353 be32_to_cpu(agf->agf_seqno),
354 be32_to_cpu(agf->agf_length));
355 printf(_("root BNO: %d CNT: %d\n"),
356 be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNOi]),
357 be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNTi]));
358 printf(_("level BNO: %d CNT: %d\n"),
359 be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNOi]),
360 be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNTi]));
361 printf(_("1st: %d last: %d cnt: %d "
362 "freeblks: %d longest: %d\n"),
363 be32_to_cpu(agf->agf_flfirst),
364 be32_to_cpu(agf->agf_fllast),
365 be32_to_cpu(agf->agf_flcount),
366 be32_to_cpu(agf->agf_freeblks),
367 be32_to_cpu(agf->agf_longest));
368 }
369 } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_DQUOT_MAGIC) {
370 struct xfs_disk_dquot *dq, dq_s;
371
372 /* memmove because *ptr may not be 8-byte aligned */
373 dq = &dq_s;
374 memmove(dq, *ptr, sizeof(struct xfs_disk_dquot));
375 printf(_("DQUOT Buffer: DQ "));
376 if (be32_to_cpu(head->oh_len) <
377 sizeof(xfs_disk_dquot_t)) {
378 printf(_("Out of space\n"));
379 }
380 else {
381 printf("\n");
382 printf(_("ver: %d flags: 0x%x id: %d \n"),
383 dq->d_version, dq->d_flags,
384 be32_to_cpu(dq->d_id));
385 printf(_("blk limits hard: %llu soft: %llu\n"),
386 (unsigned long long)
387 be64_to_cpu(dq->d_blk_hardlimit),
388 (unsigned long long)
389 be64_to_cpu(dq->d_blk_softlimit));
390 printf(_("blk count: %llu warns: %d timer: %d\n"),
391 (unsigned long long) be64_to_cpu(dq->d_bcount),
392 (int) be16_to_cpu(dq->d_bwarns),
393 be32_to_cpu(dq->d_btimer));
394 printf(_("ino limits hard: %llu soft: %llu\n"),
395 (unsigned long long)
396 be64_to_cpu(dq->d_ino_hardlimit),
397 (unsigned long long)
398 be64_to_cpu(dq->d_ino_softlimit));
399 printf(_("ino count: %llu warns: %d timer: %d\n"),
400 (unsigned long long) be64_to_cpu(dq->d_icount),
401 (int) be16_to_cpu(dq->d_iwarns),
402 be32_to_cpu(dq->d_itimer));
403 }
404 } else {
405 printf(_("BUF DATA\n"));
406 if (print_data) {
407 uint *dp = (uint *)*ptr;
408 int nums = be32_to_cpu(head->oh_len) >> 2;
409 int i = 0;
410
411 while (i < nums) {
412 if ((i % 8) == 0)
413 printf("%2x ", i);
414 printf("%8x ", *dp);
415 dp++;
416 i++;
417 if ((i % 8) == 0)
418 printf("\n");
419 }
420 printf("\n");
421 }
422 }
423 *ptr += be32_to_cpu(head->oh_len);
424 }
425 if (head && head->oh_flags & XLOG_CONTINUE_TRANS)
426 skip++;
427 return skip;
428 } /* xlog_print_trans_buffer */
429
430
431 int
432 xlog_print_trans_qoff(char **ptr, uint len)
433 {
434 xfs_qoff_logformat_t *f;
435 xfs_qoff_logformat_t lbuf;
436
437 memmove(&lbuf, *ptr, MIN(sizeof(xfs_qoff_logformat_t), len));
438 f = &lbuf;
439 *ptr += len;
440 if (len >= sizeof(xfs_qoff_logformat_t)) {
441 printf(_("QOFF: #regs: %d flags: 0x%x\n"), f->qf_size, f->qf_flags);
442 return 0;
443 } else {
444 printf(_("QOFF: Not enough data to decode further\n"));
445 return 1;
446 }
447 } /* xlog_print_trans_qoff */
448
449
450 void
451 xlog_print_trans_inode_core(
452 struct xfs_log_dinode *ip)
453 {
454 printf(_("INODE CORE\n"));
455 printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
456 ip->di_magic, ip->di_mode, (int)ip->di_version,
457 (int)ip->di_format);
458 printf(_("nlink %hd uid %d gid %d\n"),
459 ip->di_nlink, ip->di_uid, ip->di_gid);
460 printf(_("atime 0x%x mtime 0x%x ctime 0x%x\n"),
461 ip->di_atime.t_sec, ip->di_mtime.t_sec, ip->di_ctime.t_sec);
462 printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%x\n"),
463 (unsigned long long)ip->di_size, (unsigned long long)ip->di_nblocks,
464 ip->di_extsize, ip->di_nextents);
465 printf(_("naextents 0x%x forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
466 ip->di_anextents, (int)ip->di_forkoff, ip->di_dmevmask,
467 ip->di_dmstate);
468 printf(_("flags 0x%x gen 0x%x\n"),
469 ip->di_flags, ip->di_gen);
470 if (ip->di_version == 3) {
471 printf(_("flags2 0x%llx cowextsize 0x%x\n"),
472 (unsigned long long)ip->di_flags2, ip->di_cowextsize);
473 }
474 }
475
476 void
477 xlog_print_dir2_sf(
478 struct xlog *log,
479 xfs_dir2_sf_hdr_t *sfp,
480 int size)
481 {
482 xfs_ino_t ino;
483 int count;
484 int i;
485 char namebuf[257];
486 xfs_dir2_sf_entry_t *sfep;
487
488 printf(_("SHORTFORM DIRECTORY size %d\n"),
489 size);
490 /* bail out for now */
491
492 return;
493
494 printf(_("SHORTFORM DIRECTORY size %d count %d\n"),
495 size, sfp->count);
496 memmove(&ino, &(sfp->parent), sizeof(ino));
497 printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(ino));
498
499 count = sfp->count;
500 sfep = xfs_dir2_sf_firstentry(sfp);
501 for (i = 0; i < count; i++) {
502 ino = M_DIROPS(log->l_mp)->sf_get_ino(sfp, sfep);
503 memmove(namebuf, (sfep->name), sfep->namelen);
504 namebuf[sfep->namelen] = '\0';
505 printf(_("%s ino 0x%llx namelen %d\n"),
506 namebuf, (unsigned long long)ino, sfep->namelen);
507 sfep = M_DIROPS(log->l_mp)->sf_nextentry(sfp, sfep);
508 }
509 }
510
511 int
512 xlog_print_trans_inode(
513 struct xlog *log,
514 char **ptr,
515 int len,
516 int *i,
517 int num_ops,
518 int continued)
519 {
520 struct xfs_log_dinode dino;
521 struct xlog_op_header *op_head;
522 struct xfs_inode_log_format dst_lbuf;
523 struct xfs_inode_log_format src_lbuf;
524 struct xfs_inode_log_format *f;
525 int mode;
526 int size;
527 int skip_count;
528
529 /*
530 * print inode type header region
531 *
532 * memmove to ensure 8-byte alignment for the long longs in
533 * struct xfs_inode_log_format structure
534 *
535 * len can be smaller than struct xfs_inode_log_format
536 * if format data is split over operations
537 */
538 memmove(&src_lbuf, *ptr, MIN(sizeof(src_lbuf), len));
539 (*i)++; /* bump index */
540 *ptr += len;
541 if (!continued &&
542 (len == sizeof(struct xfs_inode_log_format_32) ||
543 len == sizeof(struct xfs_inode_log_format))) {
544 f = xfs_inode_item_format_convert((char*)&src_lbuf, len, &dst_lbuf);
545 printf(_("INODE: "));
546 printf(_("#regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n"),
547 f->ilf_size, (unsigned long long)f->ilf_ino,
548 f->ilf_fields, f->ilf_dsize);
549 printf(_(" blkno: %lld len: %d boff: %d\n"),
550 (long long)f->ilf_blkno, f->ilf_len, f->ilf_boffset);
551 } else {
552 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
553 f = (struct xfs_inode_log_format *)&src_lbuf;
554 printf(_("INODE: #regs: %d Not printing rest of data\n"),
555 f->ilf_size);
556 return f->ilf_size;
557 }
558
559 skip_count = f->ilf_size-1;
560
561 if (*i >= num_ops) /* end of LR */
562 return skip_count;
563
564 /* core inode comes 2nd */
565 op_head = (xlog_op_header_t *)*ptr;
566 xlog_print_op_header(op_head, *i, ptr);
567
568 if (op_head->oh_flags & XLOG_CONTINUE_TRANS) {
569 return skip_count;
570 }
571
572 memmove(&dino, *ptr, sizeof(dino));
573 mode = dino.di_mode & S_IFMT;
574 size = (int)dino.di_size;
575 xlog_print_trans_inode_core(&dino);
576 *ptr += xfs_log_dinode_size(dino.di_version);
577 skip_count--;
578
579 switch (f->ilf_fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) {
580 case XFS_ILOG_DEV:
581 printf(_("DEV inode: no extra region\n"));
582 break;
583 case XFS_ILOG_UUID:
584 printf(_("UUID inode: no extra region\n"));
585 break;
586 }
587
588 /* Only the inode core is logged */
589 if (f->ilf_size == 2)
590 return 0;
591
592 ASSERT(f->ilf_size <= 4);
593 ASSERT((f->ilf_size == 3) || (f->ilf_fields & XFS_ILOG_AFORK));
594
595 /* does anything come next */
596 op_head = (xlog_op_header_t *)*ptr;
597
598 if (f->ilf_fields & XFS_ILOG_DFORK) {
599 if (*i == num_ops-1)
600 return skip_count;
601 (*i)++;
602 xlog_print_op_header(op_head, *i, ptr);
603
604 switch (f->ilf_fields & XFS_ILOG_DFORK) {
605 case XFS_ILOG_DEXT:
606 printf(_("EXTENTS inode data\n"));
607 break;
608 case XFS_ILOG_DBROOT:
609 printf(_("BTREE inode data\n"));
610 break;
611 case XFS_ILOG_DDATA:
612 printf(_("LOCAL inode data\n"));
613 if (mode == S_IFDIR)
614 xlog_print_dir2_sf(log, (xfs_dir2_sf_hdr_t *)*ptr, size);
615 break;
616 default:
617 ASSERT((f->ilf_fields & XFS_ILOG_DFORK) == 0);
618 break;
619 }
620
621 *ptr += be32_to_cpu(op_head->oh_len);
622 if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
623 return skip_count;
624 op_head = (xlog_op_header_t *)*ptr;
625 skip_count--;
626 }
627
628 if (f->ilf_fields & XFS_ILOG_AFORK) {
629 if (*i == num_ops-1)
630 return skip_count;
631 (*i)++;
632 xlog_print_op_header(op_head, *i, ptr);
633
634 switch (f->ilf_fields & XFS_ILOG_AFORK) {
635 case XFS_ILOG_AEXT:
636 printf(_("EXTENTS attr data\n"));
637 break;
638 case XFS_ILOG_ABROOT:
639 printf(_("BTREE attr data\n"));
640 break;
641 case XFS_ILOG_ADATA:
642 printf(_("LOCAL attr data\n"));
643 if (mode == S_IFDIR)
644 xlog_print_dir2_sf(log, (xfs_dir2_sf_hdr_t *)*ptr, size);
645 break;
646 default:
647 ASSERT((f->ilf_fields & XFS_ILOG_AFORK) == 0);
648 break;
649 }
650 *ptr += be32_to_cpu(op_head->oh_len);
651 if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
652 return skip_count;
653 skip_count--;
654 }
655
656 ASSERT(skip_count == 0);
657
658 return 0;
659 } /* xlog_print_trans_inode */
660
661
662 int
663 xlog_print_trans_dquot(char **ptr, int len, int *i, int num_ops)
664 {
665 xfs_dq_logformat_t *f;
666 xfs_dq_logformat_t lbuf = {0};
667 xfs_disk_dquot_t ddq;
668 xlog_op_header_t *head = NULL;
669 int num, skip;
670
671 /*
672 * print dquot header region
673 *
674 * memmove to ensure 8-byte alignment for the long longs in
675 * xfs_dq_logformat_t structure
676 */
677 memmove(&lbuf, *ptr, MIN(sizeof(xfs_dq_logformat_t), len));
678 f = &lbuf;
679 (*i)++; /* bump index */
680 *ptr += len;
681
682 if (len == sizeof(xfs_dq_logformat_t)) {
683 printf(_("#regs: %d id: 0x%x"), f->qlf_size, f->qlf_id);
684 printf(_(" blkno: %lld len: %d boff: %d\n"),
685 (long long)f->qlf_blkno, f->qlf_len, f->qlf_boffset);
686 } else {
687 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
688 printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
689 f->qlf_size);
690 return f->qlf_size;
691 }
692 num = f->qlf_size-1;
693
694 /* Check if all regions in this log item were in the given LR ptr */
695 if (*i+num > num_ops-1) {
696 skip = num - (num_ops-1-*i);
697 num = num_ops-1-*i;
698 } else {
699 skip = 0;
700 }
701
702 while (num-- > 0) {
703 head = (xlog_op_header_t *)*ptr;
704 xlog_print_op_header(head, *i, ptr);
705 ASSERT(be32_to_cpu(head->oh_len) == sizeof(xfs_disk_dquot_t));
706 memmove(&ddq, *ptr, sizeof(xfs_disk_dquot_t));
707 printf(_("DQUOT: magic 0x%hx flags 0%ho\n"),
708 be16_to_cpu(ddq.d_magic), ddq.d_flags);
709 *ptr += be32_to_cpu(head->oh_len);
710 }
711 if (head && head->oh_flags & XLOG_CONTINUE_TRANS)
712 skip++;
713 return skip;
714 } /* xlog_print_trans_dquot */
715
716
717 STATIC int
718 xlog_print_trans_icreate(
719 char **ptr,
720 int len,
721 int *i,
722 int num_ops)
723 {
724 struct xfs_icreate_log icl_buf = {0};
725 struct xfs_icreate_log *icl;
726
727 memmove(&icl_buf, *ptr, MIN(sizeof(struct xfs_icreate_log), len));
728 icl = &icl_buf;
729 *ptr += len;
730
731 /* handle complete header only */
732 if (len != sizeof(struct xfs_icreate_log)) {
733 printf(_("ICR: split header, not printing\n"));
734 return 1; /* to skip leftover in next region */
735 }
736
737 printf(_("ICR: #ag: %d agbno: 0x%x len: %d\n"
738 " cnt: %d isize: %d gen: 0x%x\n"),
739 be32_to_cpu(icl->icl_ag), be32_to_cpu(icl->icl_agbno),
740 be32_to_cpu(icl->icl_length), be32_to_cpu(icl->icl_count),
741 be32_to_cpu(icl->icl_isize), be32_to_cpu(icl->icl_gen));
742 return 0;
743 }
744
745 /******************************************************************************
746 *
747 * Log print routines
748 *
749 ******************************************************************************
750 */
751
752 void
753 xlog_print_lseek(struct xlog *log, int fd, xfs_daddr_t blkno, int whence)
754 {
755 #define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
756 xfs_off_t offset;
757
758 if (whence == SEEK_SET)
759 offset = BBTOOFF64(blkno+log->l_logBBstart);
760 else
761 offset = BBTOOFF64(blkno);
762 if (lseek(fd, offset, whence) < 0) {
763 fprintf(stderr, _("%s: lseek to %lld failed: %s\n"),
764 progname, (long long)offset, strerror(errno));
765 exit(1);
766 }
767 } /* xlog_print_lseek */
768
769
770 void
771 print_lsn(char *string,
772 __be64 *lsn)
773 {
774 printf("%s: %u,%u", string,
775 CYCLE_LSN(be64_to_cpu(*lsn)), BLOCK_LSN(be64_to_cpu(*lsn)));
776 }
777
778
779 int
780 xlog_print_record(
781 struct xlog *log,
782 int fd,
783 int num_ops,
784 int len,
785 int *read_type,
786 char **partial_buf,
787 xlog_rec_header_t *rhead,
788 xlog_rec_ext_header_t *xhdrs,
789 int bad_hdr_warn)
790 {
791 char *buf, *ptr;
792 int read_len, skip, lost_context = 0;
793 int ret, n, i, j, k;
794
795 if (print_no_print)
796 return NO_ERROR;
797
798 if (!len) {
799 printf("\n");
800 return NO_ERROR;
801 }
802
803 /* read_len must read up to some block boundary */
804 read_len = (int) BBTOB(BTOBB(len));
805
806 /* read_type => don't malloc() new buffer, use old one */
807 if (*read_type == FULL_READ) {
808 if ((ptr = buf = malloc(read_len)) == NULL) {
809 fprintf(stderr, _("%s: xlog_print_record: malloc failed\n"), progname);
810 exit(1);
811 }
812 } else {
813 read_len -= *read_type;
814 buf = (char *)((intptr_t)(*partial_buf) + (intptr_t)(*read_type));
815 ptr = *partial_buf;
816 }
817 if ((ret = (int) read(fd, buf, read_len)) == -1) {
818 fprintf(stderr, _("%s: xlog_print_record: read error\n"), progname);
819 exit(1);
820 }
821 /* Did we overflow the end? */
822 if (*read_type == FULL_READ &&
823 BLOCK_LSN(be64_to_cpu(rhead->h_lsn)) + BTOBB(read_len) >=
824 logBBsize) {
825 *read_type = BBTOB(logBBsize - BLOCK_LSN(be64_to_cpu(rhead->h_lsn))-1);
826 *partial_buf = buf;
827 return PARTIAL_READ;
828 }
829
830 /* Did we read everything? */
831 if ((ret == 0 && read_len != 0) || ret != read_len) {
832 *read_type = ret;
833 *partial_buf = buf;
834 return PARTIAL_READ;
835 }
836 if (*read_type != FULL_READ)
837 read_len += *read_type;
838
839 /* Everything read in. Start from beginning of buffer
840 * Unpack the data, by putting the saved cycle-data back
841 * into the first word of each BB.
842 * Do some checks.
843 */
844 buf = ptr;
845 for (i = 0; ptr < buf + read_len; ptr += BBSIZE, i++) {
846 xlog_rec_header_t *rechead = (xlog_rec_header_t *)ptr;
847
848 /* sanity checks */
849 if (be32_to_cpu(rechead->h_magicno) == XLOG_HEADER_MAGIC_NUM) {
850 /* data should not have magicno as first word
851 * as it should by cycle#
852 */
853 free(buf);
854 return -1;
855 } else {
856 /* verify cycle#
857 * FIXME: cycle+1 should be a macro pv#900369
858 */
859 if (be32_to_cpu(rhead->h_cycle) !=
860 be32_to_cpu(*(__be32 *)ptr)) {
861 if ((*read_type == FULL_READ) ||
862 (be32_to_cpu(rhead->h_cycle) + 1 !=
863 be32_to_cpu(*(__be32 *)ptr))) {
864 free(buf);
865 return -1;
866 }
867 }
868 }
869
870 /* copy back the data from the header */
871 if (i < XLOG_HEADER_CYCLE_SIZE / BBSIZE) {
872 /* from 1st header */
873 *(__be32 *)ptr = rhead->h_cycle_data[i];
874 }
875 else {
876 ASSERT(xhdrs != NULL);
877 /* from extra headers */
878 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
879 k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
880 *(__be32 *)ptr = xhdrs[j-1].xh_cycle_data[k];
881 }
882
883 }
884
885 ptr = buf;
886 for (i=0; i<num_ops; i++) {
887 int continued;
888
889 xlog_op_header_t *op_head = (xlog_op_header_t *)ptr;
890
891 print_xlog_op_line();
892 xlog_print_op_header(op_head, i, &ptr);
893 continued = ((op_head->oh_flags & XLOG_WAS_CONT_TRANS) ||
894 (op_head->oh_flags & XLOG_CONTINUE_TRANS));
895
896 if (continued && be32_to_cpu(op_head->oh_len) == 0)
897 continue;
898
899 if (print_no_data) {
900 for (n = 0; n < be32_to_cpu(op_head->oh_len); n++) {
901 printf("0x%02x ", (unsigned int)*ptr);
902 if (n % 16 == 15)
903 printf("\n");
904 ptr++;
905 }
906 printf("\n");
907 continue;
908 }
909
910 /* print transaction data */
911 if (xlog_print_find_tid(be32_to_cpu(op_head->oh_tid),
912 op_head->oh_flags & XLOG_WAS_CONT_TRANS)) {
913 printf(_("Left over region from split log item\n"));
914 /* Skip this leftover bit */
915 ptr += be32_to_cpu(op_head->oh_len);
916 /* We've lost context; don't complain if next one looks bad too */
917 lost_context = 1;
918 continue;
919 }
920
921 if (be32_to_cpu(op_head->oh_len) != 0) {
922 if (*(uint *)ptr == XFS_TRANS_HEADER_MAGIC) {
923 skip = xlog_print_trans_header(&ptr,
924 be32_to_cpu(op_head->oh_len));
925 } else {
926 switch (*(unsigned short *)ptr) {
927 case XFS_LI_BUF: {
928 skip = xlog_print_trans_buffer(&ptr,
929 be32_to_cpu(op_head->oh_len),
930 &i, num_ops);
931 break;
932 }
933 case XFS_LI_ICREATE: {
934 skip = xlog_print_trans_icreate(&ptr,
935 be32_to_cpu(op_head->oh_len),
936 &i, num_ops);
937 break;
938 }
939 case XFS_LI_INODE: {
940 skip = xlog_print_trans_inode(log, &ptr,
941 be32_to_cpu(op_head->oh_len),
942 &i, num_ops, continued);
943 break;
944 }
945 case XFS_LI_DQUOT: {
946 skip = xlog_print_trans_dquot(&ptr,
947 be32_to_cpu(op_head->oh_len),
948 &i, num_ops);
949 break;
950 }
951 case XFS_LI_EFI: {
952 skip = xlog_print_trans_efi(&ptr,
953 be32_to_cpu(op_head->oh_len),
954 continued);
955 break;
956 }
957 case XFS_LI_EFD: {
958 skip = xlog_print_trans_efd(&ptr,
959 be32_to_cpu(op_head->oh_len));
960 break;
961 }
962 case XFS_LI_RUI: {
963 skip = xlog_print_trans_rui(&ptr,
964 be32_to_cpu(op_head->oh_len),
965 continued);
966 break;
967 }
968 case XFS_LI_RUD: {
969 skip = xlog_print_trans_rud(&ptr,
970 be32_to_cpu(op_head->oh_len));
971 break;
972 }
973 case XFS_LI_CUI: {
974 skip = xlog_print_trans_cui(&ptr,
975 be32_to_cpu(op_head->oh_len),
976 continued);
977 break;
978 }
979 case XFS_LI_CUD: {
980 skip = xlog_print_trans_cud(&ptr,
981 be32_to_cpu(op_head->oh_len));
982 break;
983 }
984 case XFS_LI_BUI: {
985 skip = xlog_print_trans_bui(&ptr,
986 be32_to_cpu(op_head->oh_len),
987 continued);
988 break;
989 }
990 case XFS_LI_BUD: {
991 skip = xlog_print_trans_bud(&ptr,
992 be32_to_cpu(op_head->oh_len));
993 break;
994 }
995 case XFS_LI_QUOTAOFF: {
996 skip = xlog_print_trans_qoff(&ptr,
997 be32_to_cpu(op_head->oh_len));
998 break;
999 }
1000 case XLOG_UNMOUNT_TYPE: {
1001 printf(_("Unmount filesystem\n"));
1002 skip = 0;
1003 break;
1004 }
1005 default: {
1006 if (bad_hdr_warn && !lost_context) {
1007 fprintf(stderr,
1008 _("%s: unknown log operation type (%x)\n"),
1009 progname, *(unsigned short *)ptr);
1010 if (print_exit) {
1011 free(buf);
1012 return BAD_HEADER;
1013 }
1014 } else {
1015 printf(
1016 _("Left over region from split log item\n"));
1017 }
1018 skip = 0;
1019 ptr += be32_to_cpu(op_head->oh_len);
1020 lost_context = 0;
1021 }
1022 } /* switch */
1023 } /* else */
1024 if (skip != 0)
1025 xlog_print_add_to_trans(be32_to_cpu(op_head->oh_tid), skip);
1026 }
1027 }
1028 printf("\n");
1029 free(buf);
1030 return NO_ERROR;
1031 } /* xlog_print_record */
1032
1033
1034 int
1035 xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
1036 {
1037 int i;
1038 char uub[64];
1039 int datalen,bbs;
1040
1041 if (print_no_print)
1042 return be32_to_cpu(head->h_num_logops);
1043
1044 if (!head->h_magicno)
1045 return ZEROED_LOG;
1046
1047 if (be32_to_cpu(head->h_magicno) != XLOG_HEADER_MAGIC_NUM) {
1048 if (bad_hdr_warn)
1049 printf(_("Header 0x%x wanted 0x%x\n"),
1050 be32_to_cpu(head->h_magicno),
1051 XLOG_HEADER_MAGIC_NUM);
1052 return BAD_HEADER;
1053 }
1054
1055 /* check for cleared blocks written by xlog_clear_stale_blocks() */
1056 if (!head->h_len && !head->h_crc && !head->h_prev_block &&
1057 !head->h_num_logops && !head->h_size)
1058 return CLEARED_BLKS;
1059
1060 datalen=be32_to_cpu(head->h_len);
1061 bbs=BTOBB(datalen);
1062
1063 printf(_("cycle: %d version: %d "),
1064 be32_to_cpu(head->h_cycle),
1065 be32_to_cpu(head->h_version));
1066 print_lsn(" lsn", &head->h_lsn);
1067 print_lsn(" tail_lsn", &head->h_tail_lsn);
1068 printf("\n");
1069 printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
1070 datalen,
1071 be32_to_cpu(head->h_prev_block),
1072 be32_to_cpu(head->h_num_logops));
1073
1074 if (print_overwrite) {
1075 printf(_("cycle num overwrites: "));
1076 for (i=0; i< MIN(bbs, XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++)
1077 printf("%d - 0x%x ",
1078 i,
1079 be32_to_cpu(head->h_cycle_data[i]));
1080 printf("\n");
1081 }
1082
1083 platform_uuid_unparse(&head->h_fs_uuid, uub);
1084 printf(_("uuid: %s format: "), uub);
1085 switch (be32_to_cpu(head->h_fmt)) {
1086 case XLOG_FMT_UNKNOWN:
1087 printf(_("unknown\n"));
1088 break;
1089 case XLOG_FMT_LINUX_LE:
1090 printf(_("little endian linux\n"));
1091 break;
1092 case XLOG_FMT_LINUX_BE:
1093 printf(_("big endian linux\n"));
1094 break;
1095 case XLOG_FMT_IRIX_BE:
1096 printf(_("big endian irix\n"));
1097 break;
1098 default:
1099 printf("? (%d)\n", be32_to_cpu(head->h_fmt));
1100 break;
1101 }
1102 printf(_("h_size: %d\n"), be32_to_cpu(head->h_size));
1103
1104 *len = be32_to_cpu(head->h_len);
1105 return(be32_to_cpu(head->h_num_logops));
1106 } /* xlog_print_rec_head */
1107
1108 void
1109 xlog_print_rec_xhead(xlog_rec_ext_header_t *head, int coverage)
1110 {
1111 int i;
1112
1113 print_xlog_xhdr_line();
1114 printf(_("extended-header: cycle: %d\n"), be32_to_cpu(head->xh_cycle));
1115
1116 if (print_overwrite) {
1117 printf(_("cycle num overwrites: "));
1118 for (i = 0; i < coverage; i++)
1119 printf("%d - 0x%x ",
1120 i,
1121 be32_to_cpu(head->xh_cycle_data[i]));
1122 printf("\n");
1123 }
1124 } /* xlog_print_rec_xhead */
1125
1126 static void
1127 print_xlog_bad_zeroed(xfs_daddr_t blkno)
1128 {
1129 print_stars();
1130 printf(_("* ERROR: found data after zeroed blocks block=%-21lld *\n"),
1131 (long long)blkno);
1132 print_stars();
1133 if (print_exit)
1134 xlog_exit("Bad log - data after zeroed blocks");
1135 } /* print_xlog_bad_zeroed */
1136
1137 static void
1138 print_xlog_bad_header(xfs_daddr_t blkno, char *buf)
1139 {
1140 print_stars();
1141 printf(_("* ERROR: header cycle=%-11d block=%-21lld *\n"),
1142 xlog_get_cycle(buf), (long long)blkno);
1143 print_stars();
1144 if (print_exit)
1145 xlog_exit("Bad log record header");
1146 } /* print_xlog_bad_header */
1147
1148 void
1149 print_xlog_bad_data(xfs_daddr_t blkno)
1150 {
1151 print_stars();
1152 printf(_("* ERROR: data block=%-21lld *\n"),
1153 (long long)blkno);
1154 print_stars();
1155 if (print_exit)
1156 xlog_exit("Bad data in log");
1157 } /* print_xlog_bad_data */
1158
1159 static void
1160 print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno, int num_reqd, int num_hdrs)
1161 {
1162 print_stars();
1163 printf(_("* ERROR: for header block=%lld\n"
1164 "* not enough hdrs for data length, "
1165 "required num = %d, hdr num = %d\n"),
1166 (long long)blkno, num_reqd, num_hdrs);
1167 print_stars();
1168 if (print_exit)
1169 xlog_exit(_("Not enough headers for data length."));
1170 } /* print_xlog_bad_reqd_hdrs */
1171
1172 static void
1173 xlog_reallocate_xhdrs(int num_hdrs, xlog_rec_ext_header_t **ret_xhdrs)
1174 {
1175 int len = (num_hdrs-1) * sizeof(xlog_rec_ext_header_t);
1176
1177 *ret_xhdrs = (xlog_rec_ext_header_t *)realloc(*ret_xhdrs, len);
1178 if (*ret_xhdrs == NULL) {
1179 fprintf(stderr, _("%s: xlog_print: malloc failed for ext hdrs\n"), progname);
1180 exit(1);
1181 }
1182 }
1183
1184 /* for V2 logs read each extra hdr and print it out */
1185 static int
1186 xlog_print_extended_headers(
1187 int fd,
1188 int len,
1189 xfs_daddr_t *blkno,
1190 xlog_rec_header_t *hdr,
1191 int *ret_num_hdrs,
1192 xlog_rec_ext_header_t **ret_xhdrs)
1193 {
1194 int i, j;
1195 int coverage_bb;
1196 int num_hdrs;
1197 int num_required;
1198 char xhbuf[XLOG_HEADER_SIZE];
1199 xlog_rec_ext_header_t *x;
1200
1201 num_required = howmany(len, XLOG_HEADER_CYCLE_SIZE);
1202 num_hdrs = be32_to_cpu(hdr->h_size) / XLOG_HEADER_CYCLE_SIZE;
1203 if (be32_to_cpu(hdr->h_size) % XLOG_HEADER_CYCLE_SIZE)
1204 num_hdrs++;
1205
1206 if (num_required > num_hdrs) {
1207 print_xlog_bad_reqd_hdrs((*blkno)-1, num_required, num_hdrs);
1208 }
1209
1210 if (num_hdrs == 1) {
1211 free(*ret_xhdrs);
1212 *ret_xhdrs = NULL;
1213 *ret_num_hdrs = 1;
1214 return 0;
1215 }
1216
1217 if (*ret_xhdrs == NULL || num_hdrs > *ret_num_hdrs) {
1218 xlog_reallocate_xhdrs(num_hdrs, ret_xhdrs);
1219 }
1220
1221 *ret_num_hdrs = num_hdrs;
1222
1223 /* don't include 1st header */
1224 for (i = 1, x = *ret_xhdrs; i < num_hdrs; i++, (*blkno)++, x++) {
1225 /* read one extra header blk */
1226 if (read(fd, xhbuf, 512) == 0) {
1227 printf(_("%s: physical end of log\n"), progname);
1228 print_xlog_record_line();
1229 /* reached the end so return 1 */
1230 return 1;
1231 }
1232 if (print_only_data) {
1233 printf(_("BLKNO: %lld\n"), (long long)*blkno);
1234 xlog_recover_print_data(xhbuf, 512);
1235 }
1236 else {
1237 if (i == num_hdrs - 1) {
1238 /* last header */
1239 coverage_bb = BTOBB(len) %
1240 (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
1241 }
1242 else {
1243 /* earliear header */
1244 coverage_bb = XLOG_HEADER_CYCLE_SIZE / BBSIZE;
1245 }
1246 xlog_print_rec_xhead((xlog_rec_ext_header_t*)xhbuf, coverage_bb);
1247 }
1248
1249 /* Copy from buffer into xhdrs array for later.
1250 * Could endian convert here but then code later on
1251 * will look asymmetric with the 1 hdr normal case
1252 * which does endian coversion on access.
1253 */
1254 x->xh_cycle = ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle;
1255 for (j = 0; j < XLOG_HEADER_CYCLE_SIZE / BBSIZE; j++) {
1256 x->xh_cycle_data[j] =
1257 ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle_data[j];
1258 }
1259 }
1260 return 0;
1261 }
1262
1263
1264 /*
1265 * This code is gross and needs to be rewritten.
1266 */
1267 void xfs_log_print(struct xlog *log,
1268 int fd,
1269 int print_block_start)
1270 {
1271 char hbuf[XLOG_HEADER_SIZE];
1272 xlog_rec_header_t *hdr = (xlog_rec_header_t *)&hbuf[0];
1273 xlog_rec_ext_header_t *xhdrs = NULL;
1274 int num_ops, len, num_hdrs = 1;
1275 xfs_daddr_t block_end = 0, block_start, blkno, error;
1276 xfs_daddr_t zeroed_blkno = 0, cleared_blkno = 0;
1277 int read_type = FULL_READ;
1278 char *partial_buf;
1279 int zeroed = 0;
1280 int cleared = 0;
1281 int first_hdr_found = 0;
1282
1283 logBBsize = log->l_logBBsize;
1284
1285 /*
1286 * Normally, block_start and block_end are the same value since we
1287 * are printing the entire log. However, if the start block is given,
1288 * we still end at the end of the logical log.
1289 */
1290 if ((error = xlog_print_find_oldest(log, &block_end))) {
1291 fprintf(stderr, _("%s: problem finding oldest LR\n"), progname);
1292 return;
1293 }
1294 if (print_block_start == -1)
1295 block_start = block_end;
1296 else
1297 block_start = print_block_start;
1298 xlog_print_lseek(log, fd, block_start, SEEK_SET);
1299 blkno = block_start;
1300
1301 for (;;) {
1302 if (read(fd, hbuf, 512) == 0) {
1303 printf(_("%s: physical end of log\n"), progname);
1304 print_xlog_record_line();
1305 break;
1306 }
1307 if (print_only_data) {
1308 printf(_("BLKNO: %lld\n"), (long long)blkno);
1309 xlog_recover_print_data(hbuf, 512);
1310 blkno++;
1311 goto loop;
1312 }
1313 num_ops = xlog_print_rec_head(hdr, &len, first_hdr_found);
1314 blkno++;
1315
1316 if (zeroed && num_ops != ZEROED_LOG) {
1317 printf(_("%s: after %d zeroed blocks\n"), progname, zeroed);
1318 /* once we find zeroed blocks - that's all we expect */
1319 print_xlog_bad_zeroed(blkno-1);
1320 /* reset count since we're assuming previous zeroed blocks
1321 * were bad
1322 */
1323 zeroed = 0;
1324 }
1325
1326 if (num_ops == ZEROED_LOG ||
1327 num_ops == CLEARED_BLKS ||
1328 num_ops == BAD_HEADER) {
1329 if (num_ops == ZEROED_LOG) {
1330 if (zeroed == 0)
1331 zeroed_blkno = blkno-1;
1332 zeroed++;
1333 }
1334 else if (num_ops == CLEARED_BLKS) {
1335 if (cleared == 0)
1336 cleared_blkno = blkno-1;
1337 cleared++;
1338 } else {
1339 if (!first_hdr_found)
1340 block_start = blkno;
1341 else
1342 print_xlog_bad_header(blkno-1, hbuf);
1343 }
1344
1345 goto loop;
1346 }
1347
1348 if (be32_to_cpu(hdr->h_version) == 2) {
1349 if (xlog_print_extended_headers(fd, len, &blkno, hdr, &num_hdrs, &xhdrs) != 0)
1350 break;
1351 }
1352
1353 error = xlog_print_record(log, fd, num_ops, len, &read_type, &partial_buf,
1354 hdr, xhdrs, first_hdr_found);
1355 first_hdr_found++;
1356 switch (error) {
1357 case 0: {
1358 blkno += BTOBB(len);
1359 if (print_block_start != -1 &&
1360 blkno >= block_end) /* If start specified, we */
1361 goto end; /* end early */
1362 break;
1363 }
1364 case -1: {
1365 print_xlog_bad_data(blkno-1);
1366 if (print_block_start != -1 &&
1367 blkno >= block_end) /* If start specified, */
1368 goto end; /* we end early */
1369 xlog_print_lseek(log, fd, blkno, SEEK_SET);
1370 goto loop;
1371 }
1372 case PARTIAL_READ: {
1373 print_xlog_record_line();
1374 printf(_("%s: physical end of log\n"), progname);
1375 print_xlog_record_line();
1376 blkno = 0;
1377 xlog_print_lseek(log, fd, 0, SEEK_SET);
1378 /*
1379 * We may have hit the end of the log when we started at 0.
1380 * In this case, just end.
1381 */
1382 if (block_start == 0)
1383 goto end;
1384 goto partial_log_read;
1385 }
1386 default: xlog_panic(_("illegal value"));
1387 }
1388 print_xlog_record_line();
1389 loop:
1390 if (blkno >= logBBsize) {
1391 if (cleared) {
1392 printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
1393 progname, cleared,
1394 (long long)(cleared_blkno),
1395 (long long)(cleared + cleared_blkno - 1));
1396 if (cleared == logBBsize)
1397 printf(_("%s: totally cleared log\n"), progname);
1398
1399 cleared=0;
1400 }
1401 if (zeroed) {
1402 printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
1403 progname, zeroed,
1404 (long long)(zeroed_blkno),
1405 (long long)(zeroed + zeroed_blkno - 1));
1406 if (zeroed == logBBsize)
1407 printf(_("%s: totally zeroed log\n"), progname);
1408
1409 zeroed=0;
1410 }
1411 printf(_("%s: physical end of log\n"), progname);
1412 print_xlog_record_line();
1413 break;
1414 }
1415 }
1416
1417 /* Do we need to print the first part of physical log? */
1418 if (block_start != 0) {
1419 blkno = 0;
1420 xlog_print_lseek(log, fd, 0, SEEK_SET);
1421 for (;;) {
1422 if (read(fd, hbuf, 512) == 0) {
1423 xlog_panic(_("xlog_find_head: bad read"));
1424 }
1425 if (print_only_data) {
1426 printf(_("BLKNO: %lld\n"), (long long)blkno);
1427 xlog_recover_print_data(hbuf, 512);
1428 blkno++;
1429 goto loop2;
1430 }
1431 num_ops = xlog_print_rec_head(hdr, &len, first_hdr_found);
1432 blkno++;
1433
1434 if (num_ops == ZEROED_LOG ||
1435 num_ops == CLEARED_BLKS ||
1436 num_ops == BAD_HEADER) {
1437 /* we only expect zeroed log entries or cleared log
1438 * entries at the end of the _physical_ log,
1439 * so treat them the same as bad blocks here
1440 */
1441 print_xlog_bad_header(blkno-1, hbuf);
1442
1443 if (blkno >= block_end)
1444 break;
1445 continue;
1446 }
1447
1448 if (be32_to_cpu(hdr->h_version) == 2) {
1449 if (xlog_print_extended_headers(fd, len, &blkno, hdr, &num_hdrs, &xhdrs) != 0)
1450 break;
1451 }
1452
1453 partial_log_read:
1454 error= xlog_print_record(log, fd, num_ops, len, &read_type,
1455 &partial_buf, (xlog_rec_header_t *)hbuf,
1456 xhdrs, first_hdr_found);
1457 if (read_type != FULL_READ)
1458 len -= read_type;
1459 read_type = FULL_READ;
1460 if (!error)
1461 blkno += BTOBB(len);
1462 else {
1463 print_xlog_bad_data(blkno-1);
1464 xlog_print_lseek(log, fd, blkno, SEEK_SET);
1465 goto loop2;
1466 }
1467 print_xlog_record_line();
1468 loop2:
1469 if (blkno >= block_end)
1470 break;
1471 }
1472 }
1473
1474 end:
1475 printf(_("%s: logical end of log\n"), progname);
1476 print_xlog_record_line();
1477 }
1478
1479 /*
1480 * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
1481 * (which can have different field alignments) to the native 64 bit version
1482 */
1483 struct xfs_inode_log_format *
1484 xfs_inode_item_format_convert(char *src_buf, uint len, struct xfs_inode_log_format *in_f)
1485 {
1486 struct xfs_inode_log_format_32 *in_f32;
1487
1488 /* if we have native format then just return buf without copying data */
1489 if (len == sizeof(struct xfs_inode_log_format)) {
1490 return (struct xfs_inode_log_format *)src_buf;
1491 }
1492
1493 in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
1494 in_f->ilf_type = in_f32->ilf_type;
1495 in_f->ilf_size = in_f32->ilf_size;
1496 in_f->ilf_fields = in_f32->ilf_fields;
1497 in_f->ilf_asize = in_f32->ilf_asize;
1498 in_f->ilf_dsize = in_f32->ilf_dsize;
1499 in_f->ilf_ino = in_f32->ilf_ino;
1500 /* copy biggest field of ilf_u */
1501 memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
1502 sizeof(in_f->ilf_u.__pad));
1503 in_f->ilf_blkno = in_f32->ilf_blkno;
1504 in_f->ilf_len = in_f32->ilf_len;
1505 in_f->ilf_boffset = in_f32->ilf_boffset;
1506
1507 return in_f;
1508 }