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 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
;
530 * print inode type header region
532 * memmove to ensure 8-byte alignment for the long longs in
533 * struct xfs_inode_log_format structure
535 * len can be smaller than struct xfs_inode_log_format
536 * if format data is split over operations
538 memmove(&src_lbuf
, *ptr
, MIN(sizeof(src_lbuf
), len
));
539 (*i
)++; /* bump index */
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
);
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"),
559 skip_count
= f
->ilf_size
-1;
561 if (*i
>= num_ops
) /* end of LR */
564 /* core inode comes 2nd */
565 op_head
= (xlog_op_header_t
*)*ptr
;
566 xlog_print_op_header(op_head
, *i
, ptr
);
568 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
) {
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
);
579 switch (f
->ilf_fields
& (XFS_ILOG_DEV
| XFS_ILOG_UUID
)) {
581 printf(_("DEV inode: no extra region\n"));
584 printf(_("UUID inode: no extra region\n"));
588 /* Only the inode core is logged */
589 if (f
->ilf_size
== 2)
592 ASSERT(f
->ilf_size
<= 4);
593 ASSERT((f
->ilf_size
== 3) || (f
->ilf_fields
& XFS_ILOG_AFORK
));
595 /* does anything come next */
596 op_head
= (xlog_op_header_t
*)*ptr
;
598 if (f
->ilf_fields
& XFS_ILOG_DFORK
) {
602 xlog_print_op_header(op_head
, *i
, ptr
);
604 switch (f
->ilf_fields
& XFS_ILOG_DFORK
) {
606 printf(_("EXTENTS inode data\n"));
608 case XFS_ILOG_DBROOT
:
609 printf(_("BTREE inode data\n"));
612 printf(_("LOCAL inode data\n"));
614 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
617 ASSERT((f
->ilf_fields
& XFS_ILOG_DFORK
) == 0);
621 *ptr
+= be32_to_cpu(op_head
->oh_len
);
622 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
624 op_head
= (xlog_op_header_t
*)*ptr
;
628 if (f
->ilf_fields
& XFS_ILOG_AFORK
) {
632 xlog_print_op_header(op_head
, *i
, ptr
);
634 switch (f
->ilf_fields
& XFS_ILOG_AFORK
) {
636 printf(_("EXTENTS attr data\n"));
638 case XFS_ILOG_ABROOT
:
639 printf(_("BTREE attr data\n"));
642 printf(_("LOCAL attr data\n"));
644 xlog_print_dir2_sf(log
, (xfs_dir2_sf_hdr_t
*)*ptr
, size
);
647 ASSERT((f
->ilf_fields
& XFS_ILOG_AFORK
) == 0);
650 *ptr
+= be32_to_cpu(op_head
->oh_len
);
651 if (op_head
->oh_flags
& XLOG_CONTINUE_TRANS
)
656 ASSERT(skip_count
== 0);
659 } /* xlog_print_trans_inode */
663 xlog_print_trans_dquot(char **ptr
, int len
, int *i
, int num_ops
)
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
;
672 * print dquot header region
674 * memmove to ensure 8-byte alignment for the long longs in
675 * xfs_dq_logformat_t structure
677 memmove(&lbuf
, *ptr
, MIN(sizeof(xfs_dq_logformat_t
), len
));
679 (*i
)++; /* bump index */
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
);
687 ASSERT(len
>= 4); /* must have at least 4 bytes if != 0 */
688 printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
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
);
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
);
711 if (head
&& head
->oh_flags
& XLOG_CONTINUE_TRANS
)
714 } /* xlog_print_trans_dquot */
718 xlog_print_trans_icreate(
724 struct xfs_icreate_log icl_buf
= {0};
725 struct xfs_icreate_log
*icl
;
727 memmove(&icl_buf
, *ptr
, MIN(sizeof(struct xfs_icreate_log
), len
));
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 */
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
));
745 /******************************************************************************
749 ******************************************************************************
753 xlog_print_lseek(struct xlog
*log
, int fd
, xfs_daddr_t blkno
, int whence
)
755 #define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
758 if (whence
== SEEK_SET
)
759 offset
= BBTOOFF64(blkno
+log
->l_logBBstart
);
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
));
767 } /* xlog_print_lseek */
771 print_lsn(char *string
,
774 printf("%s: %u,%u", string
,
775 CYCLE_LSN(be64_to_cpu(*lsn
)), BLOCK_LSN(be64_to_cpu(*lsn
)));
787 xlog_rec_header_t
*rhead
,
788 xlog_rec_ext_header_t
*xhdrs
,
792 int read_len
, skip
, lost_context
= 0;
803 /* read_len must read up to some block boundary */
804 read_len
= (int) BBTOB(BTOBB(len
));
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
);
813 read_len
-= *read_type
;
814 buf
= (char *)((intptr_t)(*partial_buf
) + (intptr_t)(*read_type
));
817 if ((ret
= (int) read(fd
, buf
, read_len
)) == -1) {
818 fprintf(stderr
, _("%s: xlog_print_record: read error\n"), progname
);
821 /* Did we overflow the end? */
822 if (*read_type
== FULL_READ
&&
823 BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
)) + BTOBB(read_len
) >=
825 *read_type
= BBTOB(logBBsize
- BLOCK_LSN(be64_to_cpu(rhead
->h_lsn
))-1);
830 /* Did we read everything? */
831 if ((ret
== 0 && read_len
!= 0) || ret
!= read_len
) {
836 if (*read_type
!= FULL_READ
)
837 read_len
+= *read_type
;
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.
845 for (i
= 0; ptr
< buf
+ read_len
; ptr
+= BBSIZE
, i
++) {
846 xlog_rec_header_t
*rechead
= (xlog_rec_header_t
*)ptr
;
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#
857 * FIXME: cycle+1 should be a macro pv#900369
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
))) {
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
];
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
];
886 for (i
=0; i
<num_ops
; i
++) {
889 xlog_op_header_t
*op_head
= (xlog_op_header_t
*)ptr
;
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
));
896 if (continued
&& be32_to_cpu(op_head
->oh_len
) == 0)
900 for (n
= 0; n
< be32_to_cpu(op_head
->oh_len
); n
++) {
901 printf("0x%02x ", (unsigned int)*ptr
);
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 */
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
));
926 switch (*(unsigned short *)ptr
) {
928 skip
= xlog_print_trans_buffer(&ptr
,
929 be32_to_cpu(op_head
->oh_len
),
933 case XFS_LI_ICREATE
: {
934 skip
= xlog_print_trans_icreate(&ptr
,
935 be32_to_cpu(op_head
->oh_len
),
940 skip
= xlog_print_trans_inode(log
, &ptr
,
941 be32_to_cpu(op_head
->oh_len
),
942 &i
, num_ops
, continued
);
946 skip
= xlog_print_trans_dquot(&ptr
,
947 be32_to_cpu(op_head
->oh_len
),
952 skip
= xlog_print_trans_efi(&ptr
,
953 be32_to_cpu(op_head
->oh_len
),
958 skip
= xlog_print_trans_efd(&ptr
,
959 be32_to_cpu(op_head
->oh_len
));
963 skip
= xlog_print_trans_rui(&ptr
,
964 be32_to_cpu(op_head
->oh_len
),
969 skip
= xlog_print_trans_rud(&ptr
,
970 be32_to_cpu(op_head
->oh_len
));
974 skip
= xlog_print_trans_cui(&ptr
,
975 be32_to_cpu(op_head
->oh_len
),
980 skip
= xlog_print_trans_cud(&ptr
,
981 be32_to_cpu(op_head
->oh_len
));
985 skip
= xlog_print_trans_bui(&ptr
,
986 be32_to_cpu(op_head
->oh_len
),
991 skip
= xlog_print_trans_bud(&ptr
,
992 be32_to_cpu(op_head
->oh_len
));
995 case XFS_LI_QUOTAOFF
: {
996 skip
= xlog_print_trans_qoff(&ptr
,
997 be32_to_cpu(op_head
->oh_len
));
1000 case XLOG_UNMOUNT_TYPE
: {
1001 printf(_("Unmount filesystem\n"));
1006 if (bad_hdr_warn
&& !lost_context
) {
1008 _("%s: unknown log operation type (%x)\n"),
1009 progname
, *(unsigned short *)ptr
);
1016 _("Left over region from split log item\n"));
1019 ptr
+= be32_to_cpu(op_head
->oh_len
);
1025 xlog_print_add_to_trans(be32_to_cpu(op_head
->oh_tid
), skip
);
1031 } /* xlog_print_record */
1035 xlog_print_rec_head(xlog_rec_header_t
*head
, int *len
, int bad_hdr_warn
)
1042 return be32_to_cpu(head
->h_num_logops
);
1044 if (!head
->h_magicno
)
1047 if (be32_to_cpu(head
->h_magicno
) != XLOG_HEADER_MAGIC_NUM
) {
1049 printf(_("Header 0x%x wanted 0x%x\n"),
1050 be32_to_cpu(head
->h_magicno
),
1051 XLOG_HEADER_MAGIC_NUM
);
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
;
1060 datalen
=be32_to_cpu(head
->h_len
);
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
);
1069 printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
1071 be32_to_cpu(head
->h_prev_block
),
1072 be32_to_cpu(head
->h_num_logops
));
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 ",
1079 be32_to_cpu(head
->h_cycle_data
[i
]));
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"));
1089 case XLOG_FMT_LINUX_LE
:
1090 printf(_("little endian linux\n"));
1092 case XLOG_FMT_LINUX_BE
:
1093 printf(_("big endian linux\n"));
1095 case XLOG_FMT_IRIX_BE
:
1096 printf(_("big endian irix\n"));
1099 printf("? (%d)\n", be32_to_cpu(head
->h_fmt
));
1102 printf(_("h_size: %d\n"), be32_to_cpu(head
->h_size
));
1104 *len
= be32_to_cpu(head
->h_len
);
1105 return(be32_to_cpu(head
->h_num_logops
));
1106 } /* xlog_print_rec_head */
1109 xlog_print_rec_xhead(xlog_rec_ext_header_t
*head
, int coverage
)
1113 print_xlog_xhdr_line();
1114 printf(_("extended-header: cycle: %d\n"), be32_to_cpu(head
->xh_cycle
));
1116 if (print_overwrite
) {
1117 printf(_("cycle num overwrites: "));
1118 for (i
= 0; i
< coverage
; i
++)
1119 printf("%d - 0x%x ",
1121 be32_to_cpu(head
->xh_cycle_data
[i
]));
1124 } /* xlog_print_rec_xhead */
1127 print_xlog_bad_zeroed(xfs_daddr_t blkno
)
1130 printf(_("* ERROR: found data after zeroed blocks block=%-21lld *\n"),
1134 xlog_exit("Bad log - data after zeroed blocks");
1135 } /* print_xlog_bad_zeroed */
1138 print_xlog_bad_header(xfs_daddr_t blkno
, char *buf
)
1141 printf(_("* ERROR: header cycle=%-11d block=%-21lld *\n"),
1142 xlog_get_cycle(buf
), (long long)blkno
);
1145 xlog_exit("Bad log record header");
1146 } /* print_xlog_bad_header */
1149 print_xlog_bad_data(xfs_daddr_t blkno
)
1152 printf(_("* ERROR: data block=%-21lld *\n"),
1156 xlog_exit("Bad data in log");
1157 } /* print_xlog_bad_data */
1160 print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno
, int num_reqd
, int num_hdrs
)
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
);
1169 xlog_exit(_("Not enough headers for data length."));
1170 } /* print_xlog_bad_reqd_hdrs */
1173 xlog_reallocate_xhdrs(int num_hdrs
, xlog_rec_ext_header_t
**ret_xhdrs
)
1175 int len
= (num_hdrs
-1) * sizeof(xlog_rec_ext_header_t
);
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
);
1184 /* for V2 logs read each extra hdr and print it out */
1186 xlog_print_extended_headers(
1190 xlog_rec_header_t
*hdr
,
1192 xlog_rec_ext_header_t
**ret_xhdrs
)
1198 char xhbuf
[XLOG_HEADER_SIZE
];
1199 xlog_rec_ext_header_t
*x
;
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
)
1206 if (num_required
> num_hdrs
) {
1207 print_xlog_bad_reqd_hdrs((*blkno
)-1, num_required
, num_hdrs
);
1210 if (num_hdrs
== 1) {
1217 if (*ret_xhdrs
== NULL
|| num_hdrs
> *ret_num_hdrs
) {
1218 xlog_reallocate_xhdrs(num_hdrs
, ret_xhdrs
);
1221 *ret_num_hdrs
= num_hdrs
;
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 */
1232 if (print_only_data
) {
1233 printf(_("BLKNO: %lld\n"), (long long)*blkno
);
1234 xlog_recover_print_data(xhbuf
, 512);
1237 if (i
== num_hdrs
- 1) {
1239 coverage_bb
= BTOBB(len
) %
1240 (XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
);
1243 /* earliear header */
1244 coverage_bb
= XLOG_HEADER_CYCLE_SIZE
/ BBSIZE
;
1246 xlog_print_rec_xhead((xlog_rec_ext_header_t
*)xhbuf
, coverage_bb
);
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.
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
];
1265 * This code is gross and needs to be rewritten.
1267 void xfs_log_print(struct xlog
*log
,
1269 int print_block_start
)
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
;
1281 int first_hdr_found
= 0;
1283 logBBsize
= log
->l_logBBsize
;
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.
1290 if ((error
= xlog_print_find_oldest(log
, &block_end
))) {
1291 fprintf(stderr
, _("%s: problem finding oldest LR\n"), progname
);
1294 if (print_block_start
== -1)
1295 block_start
= block_end
;
1297 block_start
= print_block_start
;
1298 xlog_print_lseek(log
, fd
, block_start
, SEEK_SET
);
1299 blkno
= block_start
;
1302 if (read(fd
, hbuf
, 512) == 0) {
1303 printf(_("%s: physical end of log\n"), progname
);
1304 print_xlog_record_line();
1307 if (print_only_data
) {
1308 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1309 xlog_recover_print_data(hbuf
, 512);
1313 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
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
1326 if (num_ops
== ZEROED_LOG
||
1327 num_ops
== CLEARED_BLKS
||
1328 num_ops
== BAD_HEADER
) {
1329 if (num_ops
== ZEROED_LOG
) {
1331 zeroed_blkno
= blkno
-1;
1334 else if (num_ops
== CLEARED_BLKS
) {
1336 cleared_blkno
= blkno
-1;
1339 if (!first_hdr_found
)
1340 block_start
= blkno
;
1342 print_xlog_bad_header(blkno
-1, hbuf
);
1348 if (be32_to_cpu(hdr
->h_version
) == 2) {
1349 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
1353 error
= xlog_print_record(log
, fd
, num_ops
, len
, &read_type
, &partial_buf
,
1354 hdr
, xhdrs
, first_hdr_found
);
1358 blkno
+= BTOBB(len
);
1359 if (print_block_start
!= -1 &&
1360 blkno
>= block_end
) /* If start specified, we */
1361 goto end
; /* end early */
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
);
1372 case PARTIAL_READ
: {
1373 print_xlog_record_line();
1374 printf(_("%s: physical end of log\n"), progname
);
1375 print_xlog_record_line();
1377 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1379 * We may have hit the end of the log when we started at 0.
1380 * In this case, just end.
1382 if (block_start
== 0)
1384 goto partial_log_read
;
1386 default: xlog_panic(_("illegal value"));
1388 print_xlog_record_line();
1390 if (blkno
>= logBBsize
) {
1392 printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
1394 (long long)(cleared_blkno
),
1395 (long long)(cleared
+ cleared_blkno
- 1));
1396 if (cleared
== logBBsize
)
1397 printf(_("%s: totally cleared log\n"), progname
);
1402 printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
1404 (long long)(zeroed_blkno
),
1405 (long long)(zeroed
+ zeroed_blkno
- 1));
1406 if (zeroed
== logBBsize
)
1407 printf(_("%s: totally zeroed log\n"), progname
);
1411 printf(_("%s: physical end of log\n"), progname
);
1412 print_xlog_record_line();
1417 /* Do we need to print the first part of physical log? */
1418 if (block_start
!= 0) {
1420 xlog_print_lseek(log
, fd
, 0, SEEK_SET
);
1422 if (read(fd
, hbuf
, 512) == 0) {
1423 xlog_panic(_("xlog_find_head: bad read"));
1425 if (print_only_data
) {
1426 printf(_("BLKNO: %lld\n"), (long long)blkno
);
1427 xlog_recover_print_data(hbuf
, 512);
1431 num_ops
= xlog_print_rec_head(hdr
, &len
, first_hdr_found
);
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
1441 print_xlog_bad_header(blkno
-1, hbuf
);
1443 if (blkno
>= block_end
)
1448 if (be32_to_cpu(hdr
->h_version
) == 2) {
1449 if (xlog_print_extended_headers(fd
, len
, &blkno
, hdr
, &num_hdrs
, &xhdrs
) != 0)
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
)
1459 read_type
= FULL_READ
;
1461 blkno
+= BTOBB(len
);
1463 print_xlog_bad_data(blkno
-1);
1464 xlog_print_lseek(log
, fd
, blkno
, SEEK_SET
);
1467 print_xlog_record_line();
1469 if (blkno
>= block_end
)
1475 printf(_("%s: logical end of log\n"), progname
);
1476 print_xlog_record_line();
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
1483 struct xfs_inode_log_format
*
1484 xfs_inode_item_format_convert(char *src_buf
, uint len
, struct xfs_inode_log_format
*in_f
)
1486 struct xfs_inode_log_format_32
*in_f32
;
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
;
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
;