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)
31 char *trans_type
[] = {
78 typedef struct xlog_split_item
{
79 struct xlog_split_item
*si_next
;
80 struct xlog_split_item
*si_prev
;
85 xlog_split_item_t
*split_list
= NULL
;
88 print_xlog_op_line(void)
90 printf("--------------------------------------"
91 "--------------------------------------\n");
92 } /* print_xlog_op_line */
95 print_xlog_xhdr_line(void)
97 printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
98 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
99 } /* print_xlog_xhdr_line */
102 print_xlog_record_line(void)
104 printf("======================================"
105 "======================================\n");
106 } /* print_xlog_record_line */
111 printf("***********************************"
112 "***********************************\n");
116 * Given a pointer to a data segment, print out the data as if it were
117 * a log operation header.
120 xlog_print_op_header(xlog_op_header_t
*op_head
,
124 xlog_op_header_t hbuf
;
127 * memmove because on 64/n32, partial reads can cause the op_head
128 * pointer to come in pointing to an odd-numbered byte
130 memmove(&hbuf
, op_head
, sizeof(xlog_op_header_t
));
132 *ptr
+= sizeof(xlog_op_header_t
);
133 printf(_("Oper (%d): tid: %x len: %d clientid: %s "), i
,
134 be32_to_cpu(op_head
->oh_tid
),
135 be32_to_cpu(op_head
->oh_len
),
136 (op_head
->oh_clientid
== XFS_TRANSACTION
? "TRANS" :
137 (op_head
->oh_clientid
== XFS_LOG
? "LOG" : "ERROR")));
138 printf(_("flags: "));
139 if (op_head
->oh_flags
) {
140 if (op_head
->oh_flags
& XLOG_START_TRANS
)
142 if (op_head
->oh_flags
& XLOG_COMMIT_TRANS
)
144 if (op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
)
146 if (op_head
->oh_flags
& XLOG_UNMOUNT_TRANS
)
148 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
150 if (op_head
->oh_flags
& XLOG_END_TRANS
)
156 } /* xlog_print_op_header */
160 xlog_print_add_to_trans(xlog_tid_t tid
,
163 xlog_split_item_t
*item
;
165 item
= (xlog_split_item_t
*)calloc(sizeof(xlog_split_item_t
), 1);
167 item
->si_skip
= skip
;
168 item
->si_next
= split_list
;
169 item
->si_prev
= NULL
;
171 split_list
->si_prev
= item
;
173 } /* xlog_print_add_to_trans */
177 xlog_print_find_tid(xlog_tid_t tid
, uint was_cont
)
179 xlog_split_item_t
*listp
= split_list
;
182 if (was_cont
!= 0) /* Not first time we have used this tid */
188 if (listp
->si_xtid
== tid
)
190 listp
= listp
->si_next
;
195 if (--listp
->si_skip
== 0) {
196 if (listp
== split_list
) { /* delete at head */
197 split_list
= listp
->si_next
;
199 split_list
->si_prev
= NULL
;
202 listp
->si_next
->si_prev
= listp
->si_prev
;
203 listp
->si_prev
->si_next
= listp
->si_next
;
208 } /* xlog_print_find_tid */
211 xlog_print_trans_header(char **ptr
, int len
)
213 xfs_trans_header_t
*h
;
216 char *magic_c
= (char *)&magic
;
220 magic
=*(__uint32_t
*)cptr
; /* XXX be32_to_cpu soon */
223 #if __BYTE_ORDER == __LITTLE_ENDIAN
225 magic_c
[3], magic_c
[2], magic_c
[1], magic_c
[0]);
228 magic_c
[0], magic_c
[1], magic_c
[2], magic_c
[3]);
231 if (len
!= sizeof(xfs_trans_header_t
)) {
232 printf(_(" Not enough data to decode further\n"));
235 h
= (xfs_trans_header_t
*)cptr
;
236 printf(_(" type: %s tid: %x num_items: %d\n"),
237 trans_type
[h
->th_type
], h
->th_tid
, h
->th_num_items
);
239 } /* xlog_print_trans_header */
243 xlog_print_trans_buffer(char **ptr
, int len
, int *i
, int num_ops
)
245 xfs_buf_log_format_t
*f
;
246 xlog_op_header_t
*head
= NULL
;
249 int bucket
, col
, buckets
;
251 xfs_buf_log_format_t lbuf
;
252 int size
, blen
, map_size
, struct_size
;
254 unsigned short flags
;
257 * memmove to ensure 8-byte alignment for the long longs in
258 * buf_log_format_t structure
260 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_buf_log_format_t
), len
));
264 ASSERT(f
->blf_type
== XFS_LI_BUF
);
266 blkno
= f
->blf_blkno
;
269 map_size
= f
->blf_map_size
;
270 flags
= f
->blf_flags
;
273 * size of the format header is dependent on the size of the bitmap, not
274 * the size of the in-memory structure. Hence the slightly obtuse
277 struct_size
= offsetof(struct xfs_buf_log_format
, blf_map_size
) + map_size
;
279 if (len
>= struct_size
) {
280 ASSERT((len
- sizeof(struct_size
)) % sizeof(int) == 0);
281 printf(_("#regs: %d start blkno: %lld (0x%llx) len: %d bmap size: %d flags: 0x%x\n"),
282 size
, (long long)blkno
, (unsigned long long)blkno
, blen
, map_size
, flags
);
286 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
287 printf(_("#regs: %d Not printing rest of data\n"), f
->blf_size
);
292 /* Check if all regions in this log item were in the given LR ptr */
293 if (*i
+num
> num_ops
-1) {
294 skip
= num
- (num_ops
-1-*i
);
301 head
= (xlog_op_header_t
*)*ptr
;
302 xlog_print_op_header(head
, *i
, ptr
);
304 printf(_("SUPER BLOCK Buffer: "));
305 if (be32_to_cpu(head
->oh_len
) < 4*8) {
306 printf(_("Out of space\n"));
310 * memmove because *ptr may not be 8-byte aligned
312 memmove(&x
, *ptr
, sizeof(__be64
));
313 memmove(&y
, *ptr
+8, sizeof(__be64
));
314 printf(_("icount: %llu ifree: %llu "),
315 (unsigned long long) be64_to_cpu(x
),
316 (unsigned long long) be64_to_cpu(y
));
317 memmove(&x
, *ptr
+16, sizeof(__be64
));
318 memmove(&y
, *ptr
+24, sizeof(__be64
));
319 printf(_("fdblks: %llu frext: %llu\n"),
320 (unsigned long long) be64_to_cpu(x
),
321 (unsigned long long) be64_to_cpu(y
));
324 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_AGI_MAGIC
) {
325 struct xfs_agi
*agi
, agi_s
;
327 /* memmove because *ptr may not be 8-byte aligned */
329 memmove(agi
, *ptr
, sizeof(struct xfs_agi
));
330 printf(_("AGI Buffer: XAGI "));
332 * v4 filesystems only contain the fields before the uuid.
333 * Even v5 filesystems don't log any field beneath it. That
334 * means that the size that is logged is almost always going to
335 * be smaller than the structure itself. Hence we need to make
336 * sure that the buffer contains all the data we want to print
337 * rather than just check against the structure size.
339 if (be32_to_cpu(head
->oh_len
) < offsetof(xfs_agi_t
, agi_uuid
) -
340 XFS_AGI_UNLINKED_BUCKETS
*sizeof(xfs_agino_t
)) {
341 printf(_("out of space\n"));
344 printf(_("ver: %d "),
345 be32_to_cpu(agi
->agi_versionnum
));
346 printf(_("seq#: %d len: %d cnt: %d root: %d\n"),
347 be32_to_cpu(agi
->agi_seqno
),
348 be32_to_cpu(agi
->agi_length
),
349 be32_to_cpu(agi
->agi_count
),
350 be32_to_cpu(agi
->agi_root
));
351 printf(_("level: %d free#: 0x%x newino: 0x%x\n"),
352 be32_to_cpu(agi
->agi_level
),
353 be32_to_cpu(agi
->agi_freecount
),
354 be32_to_cpu(agi
->agi_newino
));
355 if (be32_to_cpu(head
->oh_len
) == 128) {
357 } else if (be32_to_cpu(head
->oh_len
) == 256) {
360 if (head
->oh_flags
& XLOG_CONTINUE_TRANS
) {
361 printf(_("AGI unlinked data skipped "));
362 printf(_("(CONTINUE set, no space)\n"));
365 buckets
= XFS_AGI_UNLINKED_BUCKETS
;
367 for (bucket
= 0; bucket
< buckets
;) {
368 printf(_("bucket[%d - %d]: "), bucket
, bucket
+3);
369 for (col
= 0; col
< 4; col
++, bucket
++) {
370 if (bucket
< buckets
) {
372 be32_to_cpu(agi
->agi_unlinked
[bucket
]));
378 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_AGF_MAGIC
) {
379 struct xfs_agf
*agf
, agf_s
;
381 /* memmove because *ptr may not be 8-byte aligned */
383 memmove(agf
, *ptr
, sizeof(struct xfs_agf
));
384 printf(_("AGF Buffer: XAGF "));
386 * v4 filesystems only contain the fields before the uuid.
387 * Even v5 filesystems don't log any field beneath it. That
388 * means that the size that is logged is almost always going to
389 * be smaller than the structure itself. Hence we need to make
390 * sure that the buffer contains all the data we want to print
391 * rather than just check against the structure size.
393 if (be32_to_cpu(head
->oh_len
) < offsetof(xfs_agf_t
, agf_uuid
)) {
394 printf(_("Out of space\n"));
397 printf(_("ver: %d seq#: %d len: %d \n"),
398 be32_to_cpu(agf
->agf_versionnum
),
399 be32_to_cpu(agf
->agf_seqno
),
400 be32_to_cpu(agf
->agf_length
));
401 printf(_("root BNO: %d CNT: %d\n"),
402 be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_BNOi
]),
403 be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_CNTi
]));
404 printf(_("level BNO: %d CNT: %d\n"),
405 be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_BNOi
]),
406 be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_CNTi
]));
407 printf(_("1st: %d last: %d cnt: %d "
408 "freeblks: %d longest: %d\n"),
409 be32_to_cpu(agf
->agf_flfirst
),
410 be32_to_cpu(agf
->agf_fllast
),
411 be32_to_cpu(agf
->agf_flcount
),
412 be32_to_cpu(agf
->agf_freeblks
),
413 be32_to_cpu(agf
->agf_longest
));
415 } else if (be32_to_cpu(*(__be32
*)(*ptr
)) == XFS_DQUOT_MAGIC
) {
416 struct xfs_disk_dquot
*dq
, dq_s
;
418 /* memmove because *ptr may not be 8-byte aligned */
420 memmove(dq
, *ptr
, sizeof(struct xfs_disk_dquot
));
421 printf(_("DQUOT Buffer: DQ "));
422 if (be32_to_cpu(head
->oh_len
) <
423 sizeof(xfs_disk_dquot_t
)) {
424 printf(_("Out of space\n"));
428 printf(_("ver: %d flags: 0x%x id: %d \n"),
429 dq
->d_version
, dq
->d_flags
,
430 be32_to_cpu(dq
->d_id
));
431 printf(_("blk limits hard: %llu soft: %llu\n"),
433 be64_to_cpu(dq
->d_blk_hardlimit
),
435 be64_to_cpu(dq
->d_blk_softlimit
));
436 printf(_("blk count: %llu warns: %d timer: %d\n"),
437 (unsigned long long) be64_to_cpu(dq
->d_bcount
),
438 (int) be16_to_cpu(dq
->d_bwarns
),
439 be32_to_cpu(dq
->d_btimer
));
440 printf(_("ino limits hard: %llu soft: %llu\n"),
442 be64_to_cpu(dq
->d_ino_hardlimit
),
444 be64_to_cpu(dq
->d_ino_softlimit
));
445 printf(_("ino count: %llu warns: %d timer: %d\n"),
446 (unsigned long long) be64_to_cpu(dq
->d_icount
),
447 (int) be16_to_cpu(dq
->d_iwarns
),
448 be32_to_cpu(dq
->d_itimer
));
451 printf(_("BUF DATA\n"));
453 uint
*dp
= (uint
*)*ptr
;
454 int nums
= be32_to_cpu(head
->oh_len
) >> 2;
469 *ptr
+= be32_to_cpu(head
->oh_len
);
471 if (head
&& head
->oh_flags
& XLOG_CONTINUE_TRANS
)
474 } /* xlog_print_trans_buffer */
478 xlog_print_trans_qoff(char **ptr
, uint len
)
480 xfs_qoff_logformat_t
*f
;
481 xfs_qoff_logformat_t lbuf
;
483 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_qoff_logformat_t
), len
));
486 if (len
>= sizeof(xfs_qoff_logformat_t
)) {
487 printf(_("QOFF: #regs: %d flags: 0x%x\n"), f
->qf_size
, f
->qf_flags
);
490 printf(_("QOFF: Not enough data to decode further\n"));
493 } /* xlog_print_trans_qoff */
497 xlog_print_trans_inode_core(
498 struct xfs_log_dinode
*ip
)
500 printf(_("INODE CORE\n"));
501 printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
502 ip
->di_magic
, ip
->di_mode
, (int)ip
->di_version
,
504 printf(_("nlink %hd uid %d gid %d\n"),
505 ip
->di_nlink
, ip
->di_uid
, ip
->di_gid
);
506 printf(_("atime 0x%x mtime 0x%x ctime 0x%x\n"),
507 ip
->di_atime
.t_sec
, ip
->di_mtime
.t_sec
, ip
->di_ctime
.t_sec
);
508 printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%x\n"),
509 (unsigned long long)ip
->di_size
, (unsigned long long)ip
->di_nblocks
,
510 ip
->di_extsize
, ip
->di_nextents
);
511 printf(_("naextents 0x%x forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
512 ip
->di_anextents
, (int)ip
->di_forkoff
, ip
->di_dmevmask
,
514 printf(_("flags 0x%x gen 0x%x\n"),
515 ip
->di_flags
, ip
->di_gen
);
521 xfs_dir2_sf_hdr_t
*sfp
,
528 xfs_dir2_sf_entry_t
*sfep
;
530 printf(_("SHORTFORM DIRECTORY size %d\n"),
532 /* bail out for now */
536 printf(_("SHORTFORM DIRECTORY size %d count %d\n"),
538 memmove(&ino
, &(sfp
->parent
), sizeof(ino
));
539 printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(ino
));
542 sfep
= xfs_dir2_sf_firstentry(sfp
);
543 for (i
= 0; i
< count
; i
++) {
544 ino
= M_DIROPS(log
->l_mp
)->sf_get_ino(sfp
, sfep
);
545 memmove(namebuf
, (sfep
->name
), sfep
->namelen
);
546 namebuf
[sfep
->namelen
] = '\0';
547 printf(_("%s ino 0x%llx namelen %d\n"),
548 namebuf
, (unsigned long long)ino
, sfep
->namelen
);
549 sfep
= M_DIROPS(log
->l_mp
)->sf_nextentry(sfp
, sfep
);
554 xlog_print_trans_inode(
562 struct xfs_log_dinode dino
;
563 xlog_op_header_t
*op_head
;
564 xfs_inode_log_format_t dst_lbuf
;
565 xfs_inode_log_format_64_t src_lbuf
; /* buffer of biggest one */
566 xfs_inode_log_format_t
*f
;
571 * print inode type header region
573 * memmove to ensure 8-byte alignment for the long longs in
574 * xfs_inode_log_format_t structure
576 * len can be smaller than xfs_inode_log_format_32|64_t
577 * if format data is split over operations
579 memmove(&src_lbuf
, *ptr
, MIN(sizeof(xfs_inode_log_format_64_t
), len
));
580 (*i
)++; /* bump index */
583 (len
== sizeof(xfs_inode_log_format_32_t
) ||
584 len
== sizeof(xfs_inode_log_format_64_t
))) {
585 f
= xfs_inode_item_format_convert((char*)&src_lbuf
, len
, &dst_lbuf
);
586 printf(_("INODE: "));
587 printf(_("#regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n"),
588 f
->ilf_size
, (unsigned long long)f
->ilf_ino
,
589 f
->ilf_fields
, f
->ilf_dsize
);
590 printf(_(" blkno: %lld len: %d boff: %d\n"),
591 (long long)f
->ilf_blkno
, f
->ilf_len
, f
->ilf_boffset
);
593 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
594 f
= (xfs_inode_log_format_t
*)&src_lbuf
;
595 printf(_("INODE: #regs: %d Not printing rest of data\n"),
600 if (*i
>= num_ops
) /* end of LR */
601 return f
->ilf_size
-1;
603 /* core inode comes 2nd */
604 op_head
= (xlog_op_header_t
*)*ptr
;
605 xlog_print_op_header(op_head
, *i
, ptr
);
607 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
) {
608 return f
->ilf_size
-1;
611 memmove(&dino
, *ptr
, sizeof(dino
));
612 mode
= dino
.di_mode
& S_IFMT
;
613 size
= (int)dino
.di_size
;
614 xlog_print_trans_inode_core(&dino
);
615 *ptr
+= xfs_log_dinode_size(dino
.di_version
);
617 if (*i
== num_ops
-1 && f
->ilf_size
== 3) {
621 /* does anything come next */
622 op_head
= (xlog_op_header_t
*)*ptr
;
624 switch (f
->ilf_fields
& (XFS_ILOG_DEV
| XFS_ILOG_UUID
)) {
626 printf(_("DEV inode: no extra region\n"));
629 printf(_("UUID inode: no extra region\n"));
633 /* Only the inode core is logged */
634 if (f
->ilf_size
== 2)
637 ASSERT(f
->ilf_size
<= 4);
638 ASSERT((f
->ilf_size
== 3) || (f
->ilf_fields
& XFS_ILOG_AFORK
));
640 if (f
->ilf_fields
& XFS_ILOG_DFORK
) {
642 xlog_print_op_header(op_head
, *i
, ptr
);
644 switch (f
->ilf_fields
& XFS_ILOG_DFORK
) {
646 printf(_("EXTENTS inode data\n"));
648 case XFS_ILOG_DBROOT
:
649 printf(_("BTREE inode data\n"));
652 printf(_("LOCAL inode data\n"));
654 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
657 ASSERT((f
->ilf_fields
& XFS_ILOG_DFORK
) == 0);
661 *ptr
+= be32_to_cpu(op_head
->oh_len
);
662 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
664 op_head
= (xlog_op_header_t
*)*ptr
;
667 if (f
->ilf_fields
& XFS_ILOG_AFORK
) {
669 xlog_print_op_header(op_head
, *i
, ptr
);
671 switch (f
->ilf_fields
& XFS_ILOG_AFORK
) {
673 printf(_("EXTENTS attr data\n"));
675 case XFS_ILOG_ABROOT
:
676 printf(_("BTREE attr data\n"));
679 printf(_("LOCAL attr data\n"));
681 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
684 ASSERT((f
->ilf_fields
& XFS_ILOG_AFORK
) == 0);
687 *ptr
+= be32_to_cpu(op_head
->oh_len
);
688 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
693 } /* xlog_print_trans_inode */
697 xlog_print_trans_dquot(char **ptr
, int len
, int *i
, int num_ops
)
699 xfs_dq_logformat_t
*f
;
700 xfs_dq_logformat_t lbuf
= {0};
701 xfs_disk_dquot_t ddq
;
702 xlog_op_header_t
*head
= NULL
;
706 * print dquot header region
708 * memmove to ensure 8-byte alignment for the long longs in
709 * xfs_dq_logformat_t structure
711 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_dq_logformat_t
), len
));
713 (*i
)++; /* bump index */
716 if (len
== sizeof(xfs_dq_logformat_t
)) {
717 printf(_("#regs: %d id: 0x%x"), f
->qlf_size
, f
->qlf_id
);
718 printf(_(" blkno: %lld len: %d boff: %d\n"),
719 (long long)f
->qlf_blkno
, f
->qlf_len
, f
->qlf_boffset
);
721 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
722 printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
728 /* Check if all regions in this log item were in the given LR ptr */
729 if (*i
+num
> num_ops
-1) {
730 skip
= num
- (num_ops
-1-*i
);
737 head
= (xlog_op_header_t
*)*ptr
;
738 xlog_print_op_header(head
, *i
, ptr
);
739 ASSERT(be32_to_cpu(head
->oh_len
) == sizeof(xfs_disk_dquot_t
));
740 memmove(&ddq
, *ptr
, sizeof(xfs_disk_dquot_t
));
741 printf(_("DQUOT: magic 0x%hx flags 0%ho\n"),
742 be16_to_cpu(ddq
.d_magic
), ddq
.d_flags
);
743 *ptr
+= be32_to_cpu(head
->oh_len
);
745 if (head
&& head
->oh_flags
& XLOG_CONTINUE_TRANS
)
748 } /* xlog_print_trans_dquot */
752 xlog_print_trans_icreate(
758 struct xfs_icreate_log icl_buf
= {0};
759 struct xfs_icreate_log
*icl
;
761 memmove(&icl_buf
, *ptr
, MIN(sizeof(struct xfs_icreate_log
), len
));
765 /* handle complete header only */
766 if (len
!= sizeof(struct xfs_icreate_log
)) {
767 printf(_("ICR: split header, not printing\n"));
768 return 1; /* to skip leftover in next region */
771 printf(_("ICR: #ag: %d agbno: 0x%x len: %d\n"
772 " cnt: %d isize: %d gen: 0x%x\n"),
773 be32_to_cpu(icl
->icl_ag
), be32_to_cpu(icl
->icl_agbno
),
774 be32_to_cpu(icl
->icl_length
), be32_to_cpu(icl
->icl_count
),
775 be32_to_cpu(icl
->icl_isize
), be32_to_cpu(icl
->icl_gen
));
779 /******************************************************************************
783 ******************************************************************************
787 xlog_print_lseek(struct xlog
*log
, int fd
, xfs_daddr_t blkno
, int whence
)
789 #define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
792 if (whence
== SEEK_SET
)
793 offset
= BBTOOFF64(blkno
+log
->l_logBBstart
);
795 offset
= BBTOOFF64(blkno
);
796 if (lseek64(fd
, offset
, whence
) < 0) {
797 fprintf(stderr
, _("%s: lseek64 to %lld failed: %s\n"),
798 progname
, (long long)offset
, strerror(errno
));
801 } /* xlog_print_lseek */
805 print_lsn(char *string
,
808 printf("%s: %u,%u", string
,
809 CYCLE_LSN(be64_to_cpu(*lsn
)), BLOCK_LSN(be64_to_cpu(*lsn
)));
821 xlog_rec_header_t
*rhead
,
822 xlog_rec_ext_header_t
*xhdrs
,
826 int read_len
, skip
, lost_context
= 0;
837 /* read_len must read up to some block boundary */
838 read_len
= (int) BBTOB(BTOBB(len
));
840 /* read_type => don't malloc() new buffer, use old one */
841 if (*read_type
== FULL_READ
) {
842 if ((ptr
= buf
= malloc(read_len
)) == NULL
) {
843 fprintf(stderr
, _("%s: xlog_print_record: malloc failed\n"), progname
);
847 read_len
-= *read_type
;
848 buf
= (char *)((intptr_t)(*partial_buf
) + (intptr_t)(*read_type
));
851 if ((ret
= (int) read(fd
, buf
, read_len
)) == -1) {
852 fprintf(stderr
, _("%s: xlog_print_record: read error\n"), progname
);
855 /* Did we overflow the end? */
856 if (*read_type
== FULL_READ
&&
857 BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
)) + BTOBB(read_len
) >=
859 *read_type
= BBTOB(logBBsize
- BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
))-1);
864 /* Did we read everything? */
865 if ((ret
== 0 && read_len
!= 0) || ret
!= read_len
) {
870 if (*read_type
!= FULL_READ
)
871 read_len
+= *read_type
;
873 /* Everything read in. Start from beginning of buffer
874 * Unpack the data, by putting the saved cycle-data back
875 * into the first word of each BB.
879 for (i
= 0; ptr
< buf
+ read_len
; ptr
+= BBSIZE
, i
++) {
880 xlog_rec_header_t
*rechead
= (xlog_rec_header_t
*)ptr
;
883 if (be32_to_cpu(rechead
->h_magicno
) == XLOG_HEADER_MAGIC_NUM
) {
884 /* data should not have magicno as first word
885 * as it should by cycle#
891 * FIXME: cycle+1 should be a macro pv#900369
893 if (be32_to_cpu(rhead
->h_cycle
) !=
894 be32_to_cpu(*(__be32
*)ptr
)) {
895 if ((*read_type
== FULL_READ
) ||
896 (be32_to_cpu(rhead
->h_cycle
) + 1 !=
897 be32_to_cpu(*(__be32
*)ptr
))) {
904 /* copy back the data from the header */
905 if (i
< XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
) {
906 /* from 1st header */
907 *(__be32
*)ptr
= rhead
->h_cycle_data
[i
];
910 ASSERT(xhdrs
!= NULL
);
911 /* from extra headers */
912 j
= i
/ (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
913 k
= i
% (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
914 *(__be32
*)ptr
= xhdrs
[j
-1].xh_cycle_data
[k
];
920 for (i
=0; i
<num_ops
; i
++) {
923 xlog_op_header_t
*op_head
= (xlog_op_header_t
*)ptr
;
925 print_xlog_op_line();
926 xlog_print_op_header(op_head
, i
, &ptr
);
927 continued
= ((op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
) ||
928 (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
));
930 if (continued
&& be32_to_cpu(op_head
->oh_len
) == 0)
934 for (n
= 0; n
< be32_to_cpu(op_head
->oh_len
); n
++) {
935 printf("0x%02x ", (unsigned int)*ptr
);
944 /* print transaction data */
945 if (xlog_print_find_tid(be32_to_cpu(op_head
->oh_tid
),
946 op_head
->oh_flags
& XLOG_WAS_CONT_TRANS
)) {
947 printf(_("Left over region from split log item\n"));
948 /* Skip this leftover bit */
949 ptr
+= be32_to_cpu(op_head
->oh_len
);
950 /* We've lost context; don't complain if next one looks bad too */
955 if (be32_to_cpu(op_head
->oh_len
) != 0) {
956 if (*(uint
*)ptr
== XFS_TRANS_HEADER_MAGIC
) {
957 skip
= xlog_print_trans_header(&ptr
,
958 be32_to_cpu(op_head
->oh_len
));
960 switch (*(unsigned short *)ptr
) {
962 skip
= xlog_print_trans_buffer(&ptr
,
963 be32_to_cpu(op_head
->oh_len
),
967 case XFS_LI_ICREATE
: {
968 skip
= xlog_print_trans_icreate(&ptr
,
969 be32_to_cpu(op_head
->oh_len
),
974 skip
= xlog_print_trans_inode(log
, &ptr
,
975 be32_to_cpu(op_head
->oh_len
),
976 &i
, num_ops
, continued
);
980 skip
= xlog_print_trans_dquot(&ptr
,
981 be32_to_cpu(op_head
->oh_len
),
986 skip
= xlog_print_trans_efi(&ptr
,
987 be32_to_cpu(op_head
->oh_len
),
992 skip
= xlog_print_trans_efd(&ptr
,
993 be32_to_cpu(op_head
->oh_len
));
997 skip
= xlog_print_trans_rui(&ptr
,
998 be32_to_cpu(op_head
->oh_len
),
1003 skip
= xlog_print_trans_rud(&ptr
,
1004 be32_to_cpu(op_head
->oh_len
));
1007 case XFS_LI_QUOTAOFF
: {
1008 skip
= xlog_print_trans_qoff(&ptr
,
1009 be32_to_cpu(op_head
->oh_len
));
1012 case XLOG_UNMOUNT_TYPE
: {
1013 printf(_("Unmount filesystem\n"));
1018 if (bad_hdr_warn
&& !lost_context
) {
1020 _("%s: unknown log operation type (%x)\n"),
1021 progname
, *(unsigned short *)ptr
);
1028 _("Left over region from split log item\n"));
1031 ptr
+= be32_to_cpu(op_head
->oh_len
);
1037 xlog_print_add_to_trans(be32_to_cpu(op_head
->oh_tid
), skip
);
1043 } /* xlog_print_record */
1047 xlog_print_rec_head(xlog_rec_header_t
*head
, int *len
, int bad_hdr_warn
)
1054 return be32_to_cpu(head
->h_num_logops
);
1056 if (!head
->h_magicno
)
1059 if (be32_to_cpu(head
->h_magicno
) != XLOG_HEADER_MAGIC_NUM
) {
1061 printf(_("Header 0x%x wanted 0x%x\n"),
1062 be32_to_cpu(head
->h_magicno
),
1063 XLOG_HEADER_MAGIC_NUM
);
1067 /* check for cleared blocks written by xlog_clear_stale_blocks() */
1068 if (!head
->h_len
&& !head
->h_crc
&& !head
->h_prev_block
&&
1069 !head
->h_num_logops
&& !head
->h_size
)
1070 return CLEARED_BLKS
;
1072 datalen
=be32_to_cpu(head
->h_len
);
1075 printf(_("cycle: %d version: %d "),
1076 be32_to_cpu(head
->h_cycle
),
1077 be32_to_cpu(head
->h_version
));
1078 print_lsn(" lsn", &head
->h_lsn
);
1079 print_lsn(" tail_lsn", &head
->h_tail_lsn
);
1081 printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
1083 be32_to_cpu(head
->h_prev_block
),
1084 be32_to_cpu(head
->h_num_logops
));
1086 if (print_overwrite
) {
1087 printf(_("cycle num overwrites: "));
1088 for (i
=0; i
< MIN(bbs
, XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
); i
++)
1089 printf("%d - 0x%x ",
1091 be32_to_cpu(head
->h_cycle_data
[i
]));
1095 platform_uuid_unparse(&head
->h_fs_uuid
, uub
);
1096 printf(_("uuid: %s format: "), uub
);
1097 switch (be32_to_cpu(head
->h_fmt
)) {
1098 case XLOG_FMT_UNKNOWN
:
1099 printf(_("unknown\n"));
1101 case XLOG_FMT_LINUX_LE
:
1102 printf(_("little endian linux\n"));
1104 case XLOG_FMT_LINUX_BE
:
1105 printf(_("big endian linux\n"));
1107 case XLOG_FMT_IRIX_BE
:
1108 printf(_("big endian irix\n"));
1111 printf("? (%d)\n", be32_to_cpu(head
->h_fmt
));
1114 printf(_("h_size: %d\n"), be32_to_cpu(head
->h_size
));
1116 *len
= be32_to_cpu(head
->h_len
);
1117 return(be32_to_cpu(head
->h_num_logops
));
1118 } /* xlog_print_rec_head */
1121 xlog_print_rec_xhead(xlog_rec_ext_header_t
*head
, int coverage
)
1125 print_xlog_xhdr_line();
1126 printf(_("extended-header: cycle: %d\n"), be32_to_cpu(head
->xh_cycle
));
1128 if (print_overwrite
) {
1129 printf(_("cycle num overwrites: "));
1130 for (i
= 0; i
< coverage
; i
++)
1131 printf("%d - 0x%x ",
1133 be32_to_cpu(head
->xh_cycle_data
[i
]));
1136 } /* xlog_print_rec_xhead */
1139 print_xlog_bad_zeroed(xfs_daddr_t blkno
)
1142 printf(_("* ERROR: found data after zeroed blocks block=%-21lld *\n"),
1146 xlog_exit("Bad log - data after zeroed blocks");
1147 } /* print_xlog_bad_zeroed */
1150 print_xlog_bad_header(xfs_daddr_t blkno
, char *buf
)
1153 printf(_("* ERROR: header cycle=%-11d block=%-21lld *\n"),
1154 xlog_get_cycle(buf
), (long long)blkno
);
1157 xlog_exit("Bad log record header");
1158 } /* print_xlog_bad_header */
1161 print_xlog_bad_data(xfs_daddr_t blkno
)
1164 printf(_("* ERROR: data block=%-21lld *\n"),
1168 xlog_exit("Bad data in log");
1169 } /* print_xlog_bad_data */
1172 print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno
, int num_reqd
, int num_hdrs
)
1175 printf(_("* ERROR: for header block=%lld\n"
1176 "* not enough hdrs for data length, "
1177 "required num = %d, hdr num = %d\n"),
1178 (long long)blkno
, num_reqd
, num_hdrs
);
1181 xlog_exit(_("Not enough headers for data length."));
1182 } /* print_xlog_bad_reqd_hdrs */
1185 xlog_reallocate_xhdrs(int num_hdrs
, xlog_rec_ext_header_t
**ret_xhdrs
)
1187 int len
= (num_hdrs
-1) * sizeof(xlog_rec_ext_header_t
);
1189 *ret_xhdrs
= (xlog_rec_ext_header_t
*)realloc(*ret_xhdrs
, len
);
1190 if (*ret_xhdrs
== NULL
) {
1191 fprintf(stderr
, _("%s: xlog_print: malloc failed for ext hdrs\n"), progname
);
1196 /* for V2 logs read each extra hdr and print it out */
1198 xlog_print_extended_headers(
1202 xlog_rec_header_t
*hdr
,
1204 xlog_rec_ext_header_t
**ret_xhdrs
)
1210 char xhbuf
[XLOG_HEADER_SIZE
];
1211 xlog_rec_ext_header_t
*x
;
1213 num_required
= howmany(len
, XLOG_HEADER_CYCLE_SIZE
);
1214 num_hdrs
= be32_to_cpu(hdr
->h_size
) / XLOG_HEADER_CYCLE_SIZE
;
1215 if (be32_to_cpu(hdr
->h_size
) % XLOG_HEADER_CYCLE_SIZE
)
1218 if (num_required
> num_hdrs
) {
1219 print_xlog_bad_reqd_hdrs((*blkno
)-1, num_required
, num_hdrs
);
1222 if (num_hdrs
== 1) {
1229 if (*ret_xhdrs
== NULL
|| num_hdrs
> *ret_num_hdrs
) {
1230 xlog_reallocate_xhdrs(num_hdrs
, ret_xhdrs
);
1233 *ret_num_hdrs
= num_hdrs
;
1235 /* don't include 1st header */
1236 for (i
= 1, x
= *ret_xhdrs
; i
< num_hdrs
; i
++, (*blkno
)++, x
++) {
1237 /* read one extra header blk */
1238 if (read(fd
, xhbuf
, 512) == 0) {
1239 printf(_("%s: physical end of log\n"), progname
);
1240 print_xlog_record_line();
1241 /* reached the end so return 1 */
1244 if (print_only_data
) {
1245 printf(_("BLKNO: %lld\n"), (long long)*blkno
);
1246 xlog_recover_print_data(xhbuf
, 512);
1249 if (i
== num_hdrs
- 1) {
1251 coverage_bb
= BTOBB(len
) %
1252 (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
1255 /* earliear header */
1256 coverage_bb
= XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
;
1258 xlog_print_rec_xhead((xlog_rec_ext_header_t
*)xhbuf
, coverage_bb
);
1261 /* Copy from buffer into xhdrs array for later.
1262 * Could endian convert here but then code later on
1263 * will look asymmetric with the 1 hdr normal case
1264 * which does endian coversion on access.
1266 x
->xh_cycle
= ((xlog_rec_ext_header_t
*)xhbuf
)->xh_cycle
;
1267 for (j
= 0; j
< XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
; j
++) {
1268 x
->xh_cycle_data
[j
] =
1269 ((xlog_rec_ext_header_t
*)xhbuf
)->xh_cycle_data
[j
];
1277 * This code is gross and needs to be rewritten.
1279 void xfs_log_print(struct xlog
*log
,
1281 int print_block_start
)
1283 char hbuf
[XLOG_HEADER_SIZE
];
1284 xlog_rec_header_t
*hdr
= (xlog_rec_header_t
*)&hbuf
[0];
1285 xlog_rec_ext_header_t
*xhdrs
= NULL
;
1286 int num_ops
, len
, num_hdrs
= 1;
1287 xfs_daddr_t block_end
= 0, block_start
, blkno
, error
;
1288 xfs_daddr_t zeroed_blkno
= 0, cleared_blkno
= 0;
1289 int read_type
= FULL_READ
;
1293 int first_hdr_found
= 0;
1295 logBBsize
= log
->l_logBBsize
;
1298 * Normally, block_start and block_end are the same value since we
1299 * are printing the entire log. However, if the start block is given,
1300 * we still end at the end of the logical log.
1302 if ((error
= xlog_print_find_oldest(log
, &block_end
))) {
1303 fprintf(stderr
, _("%s: problem finding oldest LR\n"), progname
);
1306 if (print_block_start
== -1)
1307 block_start
= block_end
;
1309 block_start
= print_block_start
;
1310 xlog_print_lseek(log
, fd
, block_start
, SEEK_SET
);
1311 blkno
= block_start
;
1314 if (read(fd
, hbuf
, 512) == 0) {
1315 printf(_("%s: physical end of log\n"), progname
);
1316 print_xlog_record_line();
1319 if (print_only_data
) {
1320 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1321 xlog_recover_print_data(hbuf
, 512);
1325 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
1328 if (zeroed
&& num_ops
!= ZEROED_LOG
) {
1329 printf(_("%s: after %d zeroed blocks\n"), progname
, zeroed
);
1330 /* once we find zeroed blocks - that's all we expect */
1331 print_xlog_bad_zeroed(blkno
-1);
1332 /* reset count since we're assuming previous zeroed blocks
1338 if (num_ops
== ZEROED_LOG
||
1339 num_ops
== CLEARED_BLKS
||
1340 num_ops
== BAD_HEADER
) {
1341 if (num_ops
== ZEROED_LOG
) {
1343 zeroed_blkno
= blkno
-1;
1346 else if (num_ops
== CLEARED_BLKS
) {
1348 cleared_blkno
= blkno
-1;
1351 if (!first_hdr_found
)
1352 block_start
= blkno
;
1354 print_xlog_bad_header(blkno
-1, hbuf
);
1360 if (be32_to_cpu(hdr
->h_version
) == 2) {
1361 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
1365 error
= xlog_print_record(log
, fd
, num_ops
, len
, &read_type
, &partial_buf
,
1366 hdr
, xhdrs
, first_hdr_found
);
1370 blkno
+= BTOBB(len
);
1371 if (print_block_start
!= -1 &&
1372 blkno
>= block_end
) /* If start specified, we */
1373 goto end
; /* end early */
1377 print_xlog_bad_data(blkno
-1);
1378 if (print_block_start
!= -1 &&
1379 blkno
>= block_end
) /* If start specified, */
1380 goto end
; /* we end early */
1381 xlog_print_lseek(log
, fd
, blkno
, SEEK_SET
);
1384 case PARTIAL_READ
: {
1385 print_xlog_record_line();
1386 printf(_("%s: physical end of log\n"), progname
);
1387 print_xlog_record_line();
1389 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1391 * We may have hit the end of the log when we started at 0.
1392 * In this case, just end.
1394 if (block_start
== 0)
1396 goto partial_log_read
;
1398 default: xlog_panic(_("illegal value"));
1400 print_xlog_record_line();
1402 if (blkno
>= logBBsize
) {
1404 printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
1406 (long long)(cleared_blkno
),
1407 (long long)(cleared
+ cleared_blkno
- 1));
1408 if (cleared
== logBBsize
)
1409 printf(_("%s: totally cleared log\n"), progname
);
1414 printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
1416 (long long)(zeroed_blkno
),
1417 (long long)(zeroed
+ zeroed_blkno
- 1));
1418 if (zeroed
== logBBsize
)
1419 printf(_("%s: totally zeroed log\n"), progname
);
1423 printf(_("%s: physical end of log\n"), progname
);
1424 print_xlog_record_line();
1429 /* Do we need to print the first part of physical log? */
1430 if (block_start
!= 0) {
1432 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1434 if (read(fd
, hbuf
, 512) == 0) {
1435 xlog_panic(_("xlog_find_head: bad read"));
1437 if (print_only_data
) {
1438 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1439 xlog_recover_print_data(hbuf
, 512);
1443 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
1446 if (num_ops
== ZEROED_LOG
||
1447 num_ops
== CLEARED_BLKS
||
1448 num_ops
== BAD_HEADER
) {
1449 /* we only expect zeroed log entries or cleared log
1450 * entries at the end of the _physical_ log,
1451 * so treat them the same as bad blocks here
1453 print_xlog_bad_header(blkno
-1, hbuf
);
1455 if (blkno
>= block_end
)
1460 if (be32_to_cpu(hdr
->h_version
) == 2) {
1461 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
1466 error
= xlog_print_record(log
, fd
, num_ops
, len
, &read_type
,
1467 &partial_buf
, (xlog_rec_header_t
*)hbuf
,
1468 xhdrs
, first_hdr_found
);
1469 if (read_type
!= FULL_READ
)
1471 read_type
= FULL_READ
;
1473 blkno
+= BTOBB(len
);
1475 print_xlog_bad_data(blkno
-1);
1476 xlog_print_lseek(log
, fd
, blkno
, SEEK_SET
);
1479 print_xlog_record_line();
1481 if (blkno
>= block_end
)
1487 printf(_("%s: logical end of log\n"), progname
);
1488 print_xlog_record_line();
1492 * if necessary, convert an xfs_inode_log_format struct from 32bit or 64 bit versions
1493 * (which can have different field alignments) to the native version
1495 xfs_inode_log_format_t
*
1496 xfs_inode_item_format_convert(char *src_buf
, uint len
, xfs_inode_log_format_t
*in_f
)
1498 /* if we have native format then just return buf without copying data */
1499 if (len
== sizeof(xfs_inode_log_format_t
)) {
1500 return (xfs_inode_log_format_t
*)src_buf
;
1503 if (len
== sizeof(xfs_inode_log_format_32_t
)) {
1504 xfs_inode_log_format_32_t
*in_f32
;
1506 in_f32
= (xfs_inode_log_format_32_t
*)src_buf
;
1507 in_f
->ilf_type
= in_f32
->ilf_type
;
1508 in_f
->ilf_size
= in_f32
->ilf_size
;
1509 in_f
->ilf_fields
= in_f32
->ilf_fields
;
1510 in_f
->ilf_asize
= in_f32
->ilf_asize
;
1511 in_f
->ilf_dsize
= in_f32
->ilf_dsize
;
1512 in_f
->ilf_ino
= in_f32
->ilf_ino
;
1514 memcpy(&in_f
->ilf_u
.ilfu_uuid
, &in_f32
->ilf_u
.ilfu_uuid
, sizeof(uuid_t
));
1515 in_f
->ilf_blkno
= in_f32
->ilf_blkno
;
1516 in_f
->ilf_len
= in_f32
->ilf_len
;
1517 in_f
->ilf_boffset
= in_f32
->ilf_boffset
;
1519 xfs_inode_log_format_64_t
*in_f64
;
1521 ASSERT(len
== sizeof(xfs_inode_log_format_64_t
));
1522 in_f64
= (xfs_inode_log_format_64_t
*)src_buf
;
1523 in_f
->ilf_type
= in_f64
->ilf_type
;
1524 in_f
->ilf_size
= in_f64
->ilf_size
;
1525 in_f
->ilf_fields
= in_f64
->ilf_fields
;
1526 in_f
->ilf_asize
= in_f64
->ilf_asize
;
1527 in_f
->ilf_dsize
= in_f64
->ilf_dsize
;
1528 in_f
->ilf_ino
= in_f64
->ilf_ino
;
1530 memcpy(&in_f
->ilf_u
.ilfu_uuid
, &in_f64
->ilf_u
.ilfu_uuid
, sizeof(uuid_t
));
1531 in_f
->ilf_blkno
= in_f64
->ilf_blkno
;
1532 in_f
->ilf_len
= in_f64
->ilf_len
;
1533 in_f
->ilf_boffset
= in_f64
->ilf_boffset
;