2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
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.
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.
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
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)
32 typedef struct xlog_split_item
{
33 struct xlog_split_item
*si_next
;
34 struct xlog_split_item
*si_prev
;
39 xlog_split_item_t
*split_list
= NULL
;
42 print_xlog_op_line(void)
44 printf("--------------------------------------"
45 "--------------------------------------\n");
46 } /* print_xlog_op_line */
49 print_xlog_xhdr_line(void)
51 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
52 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
53 } /* print_xlog_xhdr_line */
56 print_xlog_record_line(void)
58 printf("======================================"
59 "======================================\n");
60 } /* print_xlog_record_line */
65 printf("***********************************"
66 "***********************************\n");
70 * Given a pointer to a data segment, print out the data as if it were
71 * a log operation header.
74 xlog_print_op_header(xlog_op_header_t
*op_head
,
78 xlog_op_header_t hbuf
;
81 * memmove because on 64/n32, partial reads can cause the op_head
82 * pointer to come in pointing to an odd-numbered byte
84 memmove(&hbuf
, op_head
, sizeof(xlog_op_header_t
));
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")));
93 if (op_head
->oh_flags
) {
94 if (op_head
->oh_flags
& XLOG_START_TRANS
)
96 if (op_head
->oh_flags
& XLOG_COMMIT_TRANS
)
98 if (op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
)
100 if (op_head
->oh_flags
& XLOG_UNMOUNT_TRANS
)
102 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
104 if (op_head
->oh_flags
& XLOG_END_TRANS
)
110 } /* xlog_print_op_header */
114 xlog_print_add_to_trans(xlog_tid_t tid
,
117 xlog_split_item_t
*item
;
119 item
= (xlog_split_item_t
*)calloc(sizeof(xlog_split_item_t
), 1);
121 item
->si_skip
= skip
;
122 item
->si_next
= split_list
;
123 item
->si_prev
= NULL
;
125 split_list
->si_prev
= item
;
127 } /* xlog_print_add_to_trans */
131 xlog_print_find_tid(xlog_tid_t tid
, uint was_cont
)
133 xlog_split_item_t
*listp
= split_list
;
136 if (was_cont
!= 0) /* Not first time we have used this tid */
142 if (listp
->si_xtid
== tid
)
144 listp
= listp
->si_next
;
149 if (--listp
->si_skip
== 0) {
150 if (listp
== split_list
) { /* delete at head */
151 split_list
= listp
->si_next
;
153 split_list
->si_prev
= NULL
;
156 listp
->si_next
->si_prev
= listp
->si_prev
;
157 listp
->si_prev
->si_next
= listp
->si_next
;
162 } /* xlog_print_find_tid */
165 xlog_print_trans_header(char **ptr
, int len
)
167 xfs_trans_header_t
*h
;
170 char *magic_c
= (char *)&magic
;
174 magic
=*(__uint32_t
*)cptr
; /* XXX be32_to_cpu soon */
177 #if __BYTE_ORDER == __LITTLE_ENDIAN
179 magic_c
[3], magic_c
[2], magic_c
[1], magic_c
[0]);
182 magic_c
[0], magic_c
[1], magic_c
[2], magic_c
[3]);
185 if (len
!= sizeof(xfs_trans_header_t
)) {
186 printf(_(" Not enough data to decode further\n"));
189 h
= (xfs_trans_header_t
*)cptr
;
190 printf(_(" tid: %x num_items: %d\n"),
191 h
->th_tid
, h
->th_num_items
);
193 } /* xlog_print_trans_header */
197 xlog_print_trans_buffer(char **ptr
, int len
, int *i
, int num_ops
)
199 xfs_buf_log_format_t
*f
;
200 xlog_op_header_t
*head
= NULL
;
203 int bucket
, col
, buckets
;
205 xfs_buf_log_format_t lbuf
;
206 int size
, blen
, map_size
, struct_size
;
208 unsigned short flags
;
211 * memmove to ensure 8-byte alignment for the long longs in
212 * buf_log_format_t structure
214 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_buf_log_format_t
), len
));
218 ASSERT(f
->blf_type
== XFS_LI_BUF
);
220 blkno
= f
->blf_blkno
;
223 map_size
= f
->blf_map_size
;
224 flags
= f
->blf_flags
;
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
231 struct_size
= offsetof(struct xfs_buf_log_format
, blf_map_size
) + map_size
;
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
);
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
);
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
);
255 head
= (xlog_op_header_t
*)*ptr
;
256 xlog_print_op_header(head
, *i
, ptr
);
258 printf(_("SUPER BLOCK Buffer: "));
259 if (be32_to_cpu(head
->oh_len
) < 4*8) {
260 printf(_("Out of space\n"));
264 * memmove because *ptr may not be 8-byte aligned
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
));
278 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_AGI_MAGIC
) {
279 struct xfs_agi
*agi
, agi_s
;
281 /* memmove because *ptr may not be 8-byte aligned */
283 memmove(agi
, *ptr
, sizeof(struct xfs_agi
));
284 printf(_("AGI Buffer: XAGI "));
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.
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"));
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) {
311 } else if (be32_to_cpu(head
->oh_len
) == 256) {
314 if (head
->oh_flags
& XLOG_CONTINUE_TRANS
) {
315 printf(_("AGI unlinked data skipped "));
316 printf(_("(CONTINUE set, no space)\n"));
319 buckets
= XFS_AGI_UNLINKED_BUCKETS
;
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
) {
326 be32_to_cpu(agi
->agi_unlinked
[bucket
]));
332 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_AGF_MAGIC
) {
333 struct xfs_agf
*agf
, agf_s
;
335 /* memmove because *ptr may not be 8-byte aligned */
337 memmove(agf
, *ptr
, sizeof(struct xfs_agf
));
338 printf(_("AGF Buffer: XAGF "));
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.
347 if (be32_to_cpu(head
->oh_len
) < offsetof(xfs_agf_t
, agf_uuid
)) {
348 printf(_("Out of space\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
));
369 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_DQUOT_MAGIC
) {
370 struct xfs_disk_dquot
*dq
, dq_s
;
372 /* memmove because *ptr may not be 8-byte aligned */
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"));
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"),
387 be64_to_cpu(dq
->d_blk_hardlimit
),
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"),
396 be64_to_cpu(dq
->d_ino_hardlimit
),
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
));
405 printf(_("BUF DATA\n"));
407 uint
*dp
= (uint
*)*ptr
;
408 int nums
= be32_to_cpu(head
->oh_len
) >> 2;
423 *ptr
+= be32_to_cpu(head
->oh_len
);
425 if (head
&& head
->oh_flags
& XLOG_CONTINUE_TRANS
)
428 } /* xlog_print_trans_buffer */
432 xlog_print_trans_qoff(char **ptr
, uint len
)
434 xfs_qoff_logformat_t
*f
;
435 xfs_qoff_logformat_t lbuf
;
437 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_qoff_logformat_t
), len
));
440 if (len
>= sizeof(xfs_qoff_logformat_t
)) {
441 printf(_("QOFF: #regs: %d flags: 0x%x\n"), f
->qf_size
, f
->qf_flags
);
444 printf(_("QOFF: Not enough data to decode further\n"));
447 } /* xlog_print_trans_qoff */
451 xlog_print_trans_inode_core(
452 struct xfs_log_dinode
*ip
)
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
,
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
,
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
);
479 xfs_dir2_sf_hdr_t
*sfp
,
486 xfs_dir2_sf_entry_t
*sfep
;
488 printf(_("SHORTFORM DIRECTORY size %d\n"),
490 /* bail out for now */
494 printf(_("SHORTFORM DIRECTORY size %d count %d\n"),
496 memmove(&ino
, &(sfp
->parent
), sizeof(ino
));
497 printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(ino
));
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
);
512 xlog_print_trans_inode(
520 struct xfs_log_dinode dino
;
521 xlog_op_header_t
*op_head
;
522 xfs_inode_log_format_t dst_lbuf
;
523 xfs_inode_log_format_64_t src_lbuf
; /* buffer of biggest one */
524 xfs_inode_log_format_t
*f
;
529 * print inode type header region
531 * memmove to ensure 8-byte alignment for the long longs in
532 * xfs_inode_log_format_t structure
534 * len can be smaller than xfs_inode_log_format_32|64_t
535 * if format data is split over operations
537 memmove(&src_lbuf
, *ptr
, MIN(sizeof(xfs_inode_log_format_64_t
), len
));
538 (*i
)++; /* bump index */
541 (len
== sizeof(xfs_inode_log_format_32_t
) ||
542 len
== sizeof(xfs_inode_log_format_64_t
))) {
543 f
= xfs_inode_item_format_convert((char*)&src_lbuf
, len
, &dst_lbuf
);
544 printf(_("INODE: "));
545 printf(_("#regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n"),
546 f
->ilf_size
, (unsigned long long)f
->ilf_ino
,
547 f
->ilf_fields
, f
->ilf_dsize
);
548 printf(_(" blkno: %lld len: %d boff: %d\n"),
549 (long long)f
->ilf_blkno
, f
->ilf_len
, f
->ilf_boffset
);
551 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
552 f
= (xfs_inode_log_format_t
*)&src_lbuf
;
553 printf(_("INODE: #regs: %d Not printing rest of data\n"),
558 if (*i
>= num_ops
) /* end of LR */
559 return f
->ilf_size
-1;
561 /* core inode comes 2nd */
562 op_head
= (xlog_op_header_t
*)*ptr
;
563 xlog_print_op_header(op_head
, *i
, ptr
);
565 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
) {
566 return f
->ilf_size
-1;
569 memmove(&dino
, *ptr
, sizeof(dino
));
570 mode
= dino
.di_mode
& S_IFMT
;
571 size
= (int)dino
.di_size
;
572 xlog_print_trans_inode_core(&dino
);
573 *ptr
+= xfs_log_dinode_size(dino
.di_version
);
575 if (*i
== num_ops
-1 && f
->ilf_size
== 3) {
579 /* does anything come next */
580 op_head
= (xlog_op_header_t
*)*ptr
;
582 switch (f
->ilf_fields
& (XFS_ILOG_DEV
| XFS_ILOG_UUID
)) {
584 printf(_("DEV inode: no extra region\n"));
587 printf(_("UUID inode: no extra region\n"));
591 /* Only the inode core is logged */
592 if (f
->ilf_size
== 2)
595 ASSERT(f
->ilf_size
<= 4);
596 ASSERT((f
->ilf_size
== 3) || (f
->ilf_fields
& XFS_ILOG_AFORK
));
598 if (f
->ilf_fields
& XFS_ILOG_DFORK
) {
600 xlog_print_op_header(op_head
, *i
, ptr
);
602 switch (f
->ilf_fields
& XFS_ILOG_DFORK
) {
604 printf(_("EXTENTS inode data\n"));
606 case XFS_ILOG_DBROOT
:
607 printf(_("BTREE inode data\n"));
610 printf(_("LOCAL inode data\n"));
612 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
615 ASSERT((f
->ilf_fields
& XFS_ILOG_DFORK
) == 0);
619 *ptr
+= be32_to_cpu(op_head
->oh_len
);
620 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
622 op_head
= (xlog_op_header_t
*)*ptr
;
625 if (f
->ilf_fields
& XFS_ILOG_AFORK
) {
627 xlog_print_op_header(op_head
, *i
, ptr
);
629 switch (f
->ilf_fields
& XFS_ILOG_AFORK
) {
631 printf(_("EXTENTS attr data\n"));
633 case XFS_ILOG_ABROOT
:
634 printf(_("BTREE attr data\n"));
637 printf(_("LOCAL attr data\n"));
639 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
642 ASSERT((f
->ilf_fields
& XFS_ILOG_AFORK
) == 0);
645 *ptr
+= be32_to_cpu(op_head
->oh_len
);
646 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
651 } /* xlog_print_trans_inode */
655 xlog_print_trans_dquot(char **ptr
, int len
, int *i
, int num_ops
)
657 xfs_dq_logformat_t
*f
;
658 xfs_dq_logformat_t lbuf
= {0};
659 xfs_disk_dquot_t ddq
;
660 xlog_op_header_t
*head
= NULL
;
664 * print dquot header region
666 * memmove to ensure 8-byte alignment for the long longs in
667 * xfs_dq_logformat_t structure
669 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_dq_logformat_t
), len
));
671 (*i
)++; /* bump index */
674 if (len
== sizeof(xfs_dq_logformat_t
)) {
675 printf(_("#regs: %d id: 0x%x"), f
->qlf_size
, f
->qlf_id
);
676 printf(_(" blkno: %lld len: %d boff: %d\n"),
677 (long long)f
->qlf_blkno
, f
->qlf_len
, f
->qlf_boffset
);
679 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
680 printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
686 /* Check if all regions in this log item were in the given LR ptr */
687 if (*i
+num
> num_ops
-1) {
688 skip
= num
- (num_ops
-1-*i
);
695 head
= (xlog_op_header_t
*)*ptr
;
696 xlog_print_op_header(head
, *i
, ptr
);
697 ASSERT(be32_to_cpu(head
->oh_len
) == sizeof(xfs_disk_dquot_t
));
698 memmove(&ddq
, *ptr
, sizeof(xfs_disk_dquot_t
));
699 printf(_("DQUOT: magic 0x%hx flags 0%ho\n"),
700 be16_to_cpu(ddq
.d_magic
), ddq
.d_flags
);
701 *ptr
+= be32_to_cpu(head
->oh_len
);
703 if (head
&& head
->oh_flags
& XLOG_CONTINUE_TRANS
)
706 } /* xlog_print_trans_dquot */
710 xlog_print_trans_icreate(
716 struct xfs_icreate_log icl_buf
= {0};
717 struct xfs_icreate_log
*icl
;
719 memmove(&icl_buf
, *ptr
, MIN(sizeof(struct xfs_icreate_log
), len
));
723 /* handle complete header only */
724 if (len
!= sizeof(struct xfs_icreate_log
)) {
725 printf(_("ICR: split header, not printing\n"));
726 return 1; /* to skip leftover in next region */
729 printf(_("ICR: #ag: %d agbno: 0x%x len: %d\n"
730 " cnt: %d isize: %d gen: 0x%x\n"),
731 be32_to_cpu(icl
->icl_ag
), be32_to_cpu(icl
->icl_agbno
),
732 be32_to_cpu(icl
->icl_length
), be32_to_cpu(icl
->icl_count
),
733 be32_to_cpu(icl
->icl_isize
), be32_to_cpu(icl
->icl_gen
));
737 /******************************************************************************
741 ******************************************************************************
745 xlog_print_lseek(struct xlog
*log
, int fd
, xfs_daddr_t blkno
, int whence
)
747 #define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
750 if (whence
== SEEK_SET
)
751 offset
= BBTOOFF64(blkno
+log
->l_logBBstart
);
753 offset
= BBTOOFF64(blkno
);
754 if (lseek64(fd
, offset
, whence
) < 0) {
755 fprintf(stderr
, _("%s: lseek64 to %lld failed: %s\n"),
756 progname
, (long long)offset
, strerror(errno
));
759 } /* xlog_print_lseek */
763 print_lsn(char *string
,
766 printf("%s: %u,%u", string
,
767 CYCLE_LSN(be64_to_cpu(*lsn
)), BLOCK_LSN(be64_to_cpu(*lsn
)));
779 xlog_rec_header_t
*rhead
,
780 xlog_rec_ext_header_t
*xhdrs
,
784 int read_len
, skip
, lost_context
= 0;
795 /* read_len must read up to some block boundary */
796 read_len
= (int) BBTOB(BTOBB(len
));
798 /* read_type => don't malloc() new buffer, use old one */
799 if (*read_type
== FULL_READ
) {
800 if ((ptr
= buf
= malloc(read_len
)) == NULL
) {
801 fprintf(stderr
, _("%s: xlog_print_record: malloc failed\n"), progname
);
805 read_len
-= *read_type
;
806 buf
= (char *)((intptr_t)(*partial_buf
) + (intptr_t)(*read_type
));
809 if ((ret
= (int) read(fd
, buf
, read_len
)) == -1) {
810 fprintf(stderr
, _("%s: xlog_print_record: read error\n"), progname
);
813 /* Did we overflow the end? */
814 if (*read_type
== FULL_READ
&&
815 BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
)) + BTOBB(read_len
) >=
817 *read_type
= BBTOB(logBBsize
- BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
))-1);
822 /* Did we read everything? */
823 if ((ret
== 0 && read_len
!= 0) || ret
!= read_len
) {
828 if (*read_type
!= FULL_READ
)
829 read_len
+= *read_type
;
831 /* Everything read in. Start from beginning of buffer
832 * Unpack the data, by putting the saved cycle-data back
833 * into the first word of each BB.
837 for (i
= 0; ptr
< buf
+ read_len
; ptr
+= BBSIZE
, i
++) {
838 xlog_rec_header_t
*rechead
= (xlog_rec_header_t
*)ptr
;
841 if (be32_to_cpu(rechead
->h_magicno
) == XLOG_HEADER_MAGIC_NUM
) {
842 /* data should not have magicno as first word
843 * as it should by cycle#
849 * FIXME: cycle+1 should be a macro pv#900369
851 if (be32_to_cpu(rhead
->h_cycle
) !=
852 be32_to_cpu(*(__be32
*)ptr
)) {
853 if ((*read_type
== FULL_READ
) ||
854 (be32_to_cpu(rhead
->h_cycle
) + 1 !=
855 be32_to_cpu(*(__be32
*)ptr
))) {
862 /* copy back the data from the header */
863 if (i
< XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
) {
864 /* from 1st header */
865 *(__be32
*)ptr
= rhead
->h_cycle_data
[i
];
868 ASSERT(xhdrs
!= NULL
);
869 /* from extra headers */
870 j
= i
/ (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
871 k
= i
% (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
872 *(__be32
*)ptr
= xhdrs
[j
-1].xh_cycle_data
[k
];
878 for (i
=0; i
<num_ops
; i
++) {
881 xlog_op_header_t
*op_head
= (xlog_op_header_t
*)ptr
;
883 print_xlog_op_line();
884 xlog_print_op_header(op_head
, i
, &ptr
);
885 continued
= ((op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
) ||
886 (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
));
888 if (continued
&& be32_to_cpu(op_head
->oh_len
) == 0)
892 for (n
= 0; n
< be32_to_cpu(op_head
->oh_len
); n
++) {
893 printf("0x%02x ", (unsigned int)*ptr
);
902 /* print transaction data */
903 if (xlog_print_find_tid(be32_to_cpu(op_head
->oh_tid
),
904 op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
)) {
905 printf(_("Left over region from split log item\n"));
906 /* Skip this leftover bit */
907 ptr
+= be32_to_cpu(op_head
->oh_len
);
908 /* We've lost context; don't complain if next one looks bad too */
913 if (be32_to_cpu(op_head
->oh_len
) != 0) {
914 if (*(uint
*)ptr
== XFS_TRANS_HEADER_MAGIC
) {
915 skip
= xlog_print_trans_header(&ptr
,
916 be32_to_cpu(op_head
->oh_len
));
918 switch (*(unsigned short *)ptr
) {
920 skip
= xlog_print_trans_buffer(&ptr
,
921 be32_to_cpu(op_head
->oh_len
),
925 case XFS_LI_ICREATE
: {
926 skip
= xlog_print_trans_icreate(&ptr
,
927 be32_to_cpu(op_head
->oh_len
),
932 skip
= xlog_print_trans_inode(log
, &ptr
,
933 be32_to_cpu(op_head
->oh_len
),
934 &i
, num_ops
, continued
);
938 skip
= xlog_print_trans_dquot(&ptr
,
939 be32_to_cpu(op_head
->oh_len
),
944 skip
= xlog_print_trans_efi(&ptr
,
945 be32_to_cpu(op_head
->oh_len
),
950 skip
= xlog_print_trans_efd(&ptr
,
951 be32_to_cpu(op_head
->oh_len
));
955 skip
= xlog_print_trans_rui(&ptr
,
956 be32_to_cpu(op_head
->oh_len
),
961 skip
= xlog_print_trans_rud(&ptr
,
962 be32_to_cpu(op_head
->oh_len
));
966 skip
= xlog_print_trans_cui(&ptr
,
967 be32_to_cpu(op_head
->oh_len
),
972 skip
= xlog_print_trans_cud(&ptr
,
973 be32_to_cpu(op_head
->oh_len
));
977 skip
= xlog_print_trans_bui(&ptr
,
978 be32_to_cpu(op_head
->oh_len
),
983 skip
= xlog_print_trans_bud(&ptr
,
984 be32_to_cpu(op_head
->oh_len
));
987 case XFS_LI_QUOTAOFF
: {
988 skip
= xlog_print_trans_qoff(&ptr
,
989 be32_to_cpu(op_head
->oh_len
));
992 case XLOG_UNMOUNT_TYPE
: {
993 printf(_("Unmount filesystem\n"));
998 if (bad_hdr_warn
&& !lost_context
) {
1000 _("%s: unknown log operation type (%x)\n"),
1001 progname
, *(unsigned short *)ptr
);
1008 _("Left over region from split log item\n"));
1011 ptr
+= be32_to_cpu(op_head
->oh_len
);
1017 xlog_print_add_to_trans(be32_to_cpu(op_head
->oh_tid
), skip
);
1023 } /* xlog_print_record */
1027 xlog_print_rec_head(xlog_rec_header_t
*head
, int *len
, int bad_hdr_warn
)
1034 return be32_to_cpu(head
->h_num_logops
);
1036 if (!head
->h_magicno
)
1039 if (be32_to_cpu(head
->h_magicno
) != XLOG_HEADER_MAGIC_NUM
) {
1041 printf(_("Header 0x%x wanted 0x%x\n"),
1042 be32_to_cpu(head
->h_magicno
),
1043 XLOG_HEADER_MAGIC_NUM
);
1047 /* check for cleared blocks written by xlog_clear_stale_blocks() */
1048 if (!head
->h_len
&& !head
->h_crc
&& !head
->h_prev_block
&&
1049 !head
->h_num_logops
&& !head
->h_size
)
1050 return CLEARED_BLKS
;
1052 datalen
=be32_to_cpu(head
->h_len
);
1055 printf(_("cycle: %d version: %d "),
1056 be32_to_cpu(head
->h_cycle
),
1057 be32_to_cpu(head
->h_version
));
1058 print_lsn(" lsn", &head
->h_lsn
);
1059 print_lsn(" tail_lsn", &head
->h_tail_lsn
);
1061 printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
1063 be32_to_cpu(head
->h_prev_block
),
1064 be32_to_cpu(head
->h_num_logops
));
1066 if (print_overwrite
) {
1067 printf(_("cycle num overwrites: "));
1068 for (i
=0; i
< MIN(bbs
, XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
); i
++)
1069 printf("%d - 0x%x ",
1071 be32_to_cpu(head
->h_cycle_data
[i
]));
1075 platform_uuid_unparse(&head
->h_fs_uuid
, uub
);
1076 printf(_("uuid: %s format: "), uub
);
1077 switch (be32_to_cpu(head
->h_fmt
)) {
1078 case XLOG_FMT_UNKNOWN
:
1079 printf(_("unknown\n"));
1081 case XLOG_FMT_LINUX_LE
:
1082 printf(_("little endian linux\n"));
1084 case XLOG_FMT_LINUX_BE
:
1085 printf(_("big endian linux\n"));
1087 case XLOG_FMT_IRIX_BE
:
1088 printf(_("big endian irix\n"));
1091 printf("? (%d)\n", be32_to_cpu(head
->h_fmt
));
1094 printf(_("h_size: %d\n"), be32_to_cpu(head
->h_size
));
1096 *len
= be32_to_cpu(head
->h_len
);
1097 return(be32_to_cpu(head
->h_num_logops
));
1098 } /* xlog_print_rec_head */
1101 xlog_print_rec_xhead(xlog_rec_ext_header_t
*head
, int coverage
)
1105 print_xlog_xhdr_line();
1106 printf(_("extended-header: cycle: %d\n"), be32_to_cpu(head
->xh_cycle
));
1108 if (print_overwrite
) {
1109 printf(_("cycle num overwrites: "));
1110 for (i
= 0; i
< coverage
; i
++)
1111 printf("%d - 0x%x ",
1113 be32_to_cpu(head
->xh_cycle_data
[i
]));
1116 } /* xlog_print_rec_xhead */
1119 print_xlog_bad_zeroed(xfs_daddr_t blkno
)
1122 printf(_("* ERROR: found data after zeroed blocks block=%-21lld *\n"),
1126 xlog_exit("Bad log - data after zeroed blocks");
1127 } /* print_xlog_bad_zeroed */
1130 print_xlog_bad_header(xfs_daddr_t blkno
, char *buf
)
1133 printf(_("* ERROR: header cycle=%-11d block=%-21lld *\n"),
1134 xlog_get_cycle(buf
), (long long)blkno
);
1137 xlog_exit("Bad log record header");
1138 } /* print_xlog_bad_header */
1141 print_xlog_bad_data(xfs_daddr_t blkno
)
1144 printf(_("* ERROR: data block=%-21lld *\n"),
1148 xlog_exit("Bad data in log");
1149 } /* print_xlog_bad_data */
1152 print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno
, int num_reqd
, int num_hdrs
)
1155 printf(_("* ERROR: for header block=%lld\n"
1156 "* not enough hdrs for data length, "
1157 "required num = %d, hdr num = %d\n"),
1158 (long long)blkno
, num_reqd
, num_hdrs
);
1161 xlog_exit(_("Not enough headers for data length."));
1162 } /* print_xlog_bad_reqd_hdrs */
1165 xlog_reallocate_xhdrs(int num_hdrs
, xlog_rec_ext_header_t
**ret_xhdrs
)
1167 int len
= (num_hdrs
-1) * sizeof(xlog_rec_ext_header_t
);
1169 *ret_xhdrs
= (xlog_rec_ext_header_t
*)realloc(*ret_xhdrs
, len
);
1170 if (*ret_xhdrs
== NULL
) {
1171 fprintf(stderr
, _("%s: xlog_print: malloc failed for ext hdrs\n"), progname
);
1176 /* for V2 logs read each extra hdr and print it out */
1178 xlog_print_extended_headers(
1182 xlog_rec_header_t
*hdr
,
1184 xlog_rec_ext_header_t
**ret_xhdrs
)
1190 char xhbuf
[XLOG_HEADER_SIZE
];
1191 xlog_rec_ext_header_t
*x
;
1193 num_required
= howmany(len
, XLOG_HEADER_CYCLE_SIZE
);
1194 num_hdrs
= be32_to_cpu(hdr
->h_size
) / XLOG_HEADER_CYCLE_SIZE
;
1195 if (be32_to_cpu(hdr
->h_size
) % XLOG_HEADER_CYCLE_SIZE
)
1198 if (num_required
> num_hdrs
) {
1199 print_xlog_bad_reqd_hdrs((*blkno
)-1, num_required
, num_hdrs
);
1202 if (num_hdrs
== 1) {
1209 if (*ret_xhdrs
== NULL
|| num_hdrs
> *ret_num_hdrs
) {
1210 xlog_reallocate_xhdrs(num_hdrs
, ret_xhdrs
);
1213 *ret_num_hdrs
= num_hdrs
;
1215 /* don't include 1st header */
1216 for (i
= 1, x
= *ret_xhdrs
; i
< num_hdrs
; i
++, (*blkno
)++, x
++) {
1217 /* read one extra header blk */
1218 if (read(fd
, xhbuf
, 512) == 0) {
1219 printf(_("%s: physical end of log\n"), progname
);
1220 print_xlog_record_line();
1221 /* reached the end so return 1 */
1224 if (print_only_data
) {
1225 printf(_("BLKNO: %lld\n"), (long long)*blkno
);
1226 xlog_recover_print_data(xhbuf
, 512);
1229 if (i
== num_hdrs
- 1) {
1231 coverage_bb
= BTOBB(len
) %
1232 (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
1235 /* earliear header */
1236 coverage_bb
= XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
;
1238 xlog_print_rec_xhead((xlog_rec_ext_header_t
*)xhbuf
, coverage_bb
);
1241 /* Copy from buffer into xhdrs array for later.
1242 * Could endian convert here but then code later on
1243 * will look asymmetric with the 1 hdr normal case
1244 * which does endian coversion on access.
1246 x
->xh_cycle
= ((xlog_rec_ext_header_t
*)xhbuf
)->xh_cycle
;
1247 for (j
= 0; j
< XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
; j
++) {
1248 x
->xh_cycle_data
[j
] =
1249 ((xlog_rec_ext_header_t
*)xhbuf
)->xh_cycle_data
[j
];
1257 * This code is gross and needs to be rewritten.
1259 void xfs_log_print(struct xlog
*log
,
1261 int print_block_start
)
1263 char hbuf
[XLOG_HEADER_SIZE
];
1264 xlog_rec_header_t
*hdr
= (xlog_rec_header_t
*)&hbuf
[0];
1265 xlog_rec_ext_header_t
*xhdrs
= NULL
;
1266 int num_ops
, len
, num_hdrs
= 1;
1267 xfs_daddr_t block_end
= 0, block_start
, blkno
, error
;
1268 xfs_daddr_t zeroed_blkno
= 0, cleared_blkno
= 0;
1269 int read_type
= FULL_READ
;
1273 int first_hdr_found
= 0;
1275 logBBsize
= log
->l_logBBsize
;
1278 * Normally, block_start and block_end are the same value since we
1279 * are printing the entire log. However, if the start block is given,
1280 * we still end at the end of the logical log.
1282 if ((error
= xlog_print_find_oldest(log
, &block_end
))) {
1283 fprintf(stderr
, _("%s: problem finding oldest LR\n"), progname
);
1286 if (print_block_start
== -1)
1287 block_start
= block_end
;
1289 block_start
= print_block_start
;
1290 xlog_print_lseek(log
, fd
, block_start
, SEEK_SET
);
1291 blkno
= block_start
;
1294 if (read(fd
, hbuf
, 512) == 0) {
1295 printf(_("%s: physical end of log\n"), progname
);
1296 print_xlog_record_line();
1299 if (print_only_data
) {
1300 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1301 xlog_recover_print_data(hbuf
, 512);
1305 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
1308 if (zeroed
&& num_ops
!= ZEROED_LOG
) {
1309 printf(_("%s: after %d zeroed blocks\n"), progname
, zeroed
);
1310 /* once we find zeroed blocks - that's all we expect */
1311 print_xlog_bad_zeroed(blkno
-1);
1312 /* reset count since we're assuming previous zeroed blocks
1318 if (num_ops
== ZEROED_LOG
||
1319 num_ops
== CLEARED_BLKS
||
1320 num_ops
== BAD_HEADER
) {
1321 if (num_ops
== ZEROED_LOG
) {
1323 zeroed_blkno
= blkno
-1;
1326 else if (num_ops
== CLEARED_BLKS
) {
1328 cleared_blkno
= blkno
-1;
1331 if (!first_hdr_found
)
1332 block_start
= blkno
;
1334 print_xlog_bad_header(blkno
-1, hbuf
);
1340 if (be32_to_cpu(hdr
->h_version
) == 2) {
1341 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
1345 error
= xlog_print_record(log
, fd
, num_ops
, len
, &read_type
, &partial_buf
,
1346 hdr
, xhdrs
, first_hdr_found
);
1350 blkno
+= BTOBB(len
);
1351 if (print_block_start
!= -1 &&
1352 blkno
>= block_end
) /* If start specified, we */
1353 goto end
; /* end early */
1357 print_xlog_bad_data(blkno
-1);
1358 if (print_block_start
!= -1 &&
1359 blkno
>= block_end
) /* If start specified, */
1360 goto end
; /* we end early */
1361 xlog_print_lseek(log
, fd
, blkno
, SEEK_SET
);
1364 case PARTIAL_READ
: {
1365 print_xlog_record_line();
1366 printf(_("%s: physical end of log\n"), progname
);
1367 print_xlog_record_line();
1369 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1371 * We may have hit the end of the log when we started at 0.
1372 * In this case, just end.
1374 if (block_start
== 0)
1376 goto partial_log_read
;
1378 default: xlog_panic(_("illegal value"));
1380 print_xlog_record_line();
1382 if (blkno
>= logBBsize
) {
1384 printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
1386 (long long)(cleared_blkno
),
1387 (long long)(cleared
+ cleared_blkno
- 1));
1388 if (cleared
== logBBsize
)
1389 printf(_("%s: totally cleared log\n"), progname
);
1394 printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
1396 (long long)(zeroed_blkno
),
1397 (long long)(zeroed
+ zeroed_blkno
- 1));
1398 if (zeroed
== logBBsize
)
1399 printf(_("%s: totally zeroed log\n"), progname
);
1403 printf(_("%s: physical end of log\n"), progname
);
1404 print_xlog_record_line();
1409 /* Do we need to print the first part of physical log? */
1410 if (block_start
!= 0) {
1412 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1414 if (read(fd
, hbuf
, 512) == 0) {
1415 xlog_panic(_("xlog_find_head: bad read"));
1417 if (print_only_data
) {
1418 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1419 xlog_recover_print_data(hbuf
, 512);
1423 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
1426 if (num_ops
== ZEROED_LOG
||
1427 num_ops
== CLEARED_BLKS
||
1428 num_ops
== BAD_HEADER
) {
1429 /* we only expect zeroed log entries or cleared log
1430 * entries at the end of the _physical_ log,
1431 * so treat them the same as bad blocks here
1433 print_xlog_bad_header(blkno
-1, hbuf
);
1435 if (blkno
>= block_end
)
1440 if (be32_to_cpu(hdr
->h_version
) == 2) {
1441 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
1446 error
= xlog_print_record(log
, fd
, num_ops
, len
, &read_type
,
1447 &partial_buf
, (xlog_rec_header_t
*)hbuf
,
1448 xhdrs
, first_hdr_found
);
1449 if (read_type
!= FULL_READ
)
1451 read_type
= FULL_READ
;
1453 blkno
+= BTOBB(len
);
1455 print_xlog_bad_data(blkno
-1);
1456 xlog_print_lseek(log
, fd
, blkno
, SEEK_SET
);
1459 print_xlog_record_line();
1461 if (blkno
>= block_end
)
1467 printf(_("%s: logical end of log\n"), progname
);
1468 print_xlog_record_line();
1472 * if necessary, convert an xfs_inode_log_format struct from 32bit or 64 bit versions
1473 * (which can have different field alignments) to the native version
1475 xfs_inode_log_format_t
*
1476 xfs_inode_item_format_convert(char *src_buf
, uint len
, xfs_inode_log_format_t
*in_f
)
1478 /* if we have native format then just return buf without copying data */
1479 if (len
== sizeof(xfs_inode_log_format_t
)) {
1480 return (xfs_inode_log_format_t
*)src_buf
;
1483 if (len
== sizeof(xfs_inode_log_format_32_t
)) {
1484 xfs_inode_log_format_32_t
*in_f32
;
1486 in_f32
= (xfs_inode_log_format_32_t
*)src_buf
;
1487 in_f
->ilf_type
= in_f32
->ilf_type
;
1488 in_f
->ilf_size
= in_f32
->ilf_size
;
1489 in_f
->ilf_fields
= in_f32
->ilf_fields
;
1490 in_f
->ilf_asize
= in_f32
->ilf_asize
;
1491 in_f
->ilf_dsize
= in_f32
->ilf_dsize
;
1492 in_f
->ilf_ino
= in_f32
->ilf_ino
;
1494 memcpy(&in_f
->ilf_u
.ilfu_uuid
, &in_f32
->ilf_u
.ilfu_uuid
, sizeof(uuid_t
));
1495 in_f
->ilf_blkno
= in_f32
->ilf_blkno
;
1496 in_f
->ilf_len
= in_f32
->ilf_len
;
1497 in_f
->ilf_boffset
= in_f32
->ilf_boffset
;
1499 xfs_inode_log_format_64_t
*in_f64
;
1501 ASSERT(len
== sizeof(xfs_inode_log_format_64_t
));
1502 in_f64
= (xfs_inode_log_format_64_t
*)src_buf
;
1503 in_f
->ilf_type
= in_f64
->ilf_type
;
1504 in_f
->ilf_size
= in_f64
->ilf_size
;
1505 in_f
->ilf_fields
= in_f64
->ilf_fields
;
1506 in_f
->ilf_asize
= in_f64
->ilf_asize
;
1507 in_f
->ilf_dsize
= in_f64
->ilf_dsize
;
1508 in_f
->ilf_ino
= in_f64
->ilf_ino
;
1510 memcpy(&in_f
->ilf_u
.ilfu_uuid
, &in_f64
->ilf_u
.ilfu_uuid
, sizeof(uuid_t
));
1511 in_f
->ilf_blkno
= in_f64
->ilf_blkno
;
1512 in_f
->ilf_len
= in_f64
->ilf_len
;
1513 in_f
->ilf_boffset
= in_f64
->ilf_boffset
;