1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * Copyright (c) 2016 Oracle, Inc.
12 /* Extent Free Items */
18 struct xfs_efi_log_format
*dst_efi_fmt
,
22 uint nextents
= ((xfs_efi_log_format_t
*)buf
)->efi_nextents
;
23 uint dst_len
= sizeof(xfs_efi_log_format_t
) + (nextents
- 1) * sizeof(xfs_extent_t
);
24 uint len32
= sizeof(xfs_efi_log_format_32_t
) + (nextents
- 1) * sizeof(xfs_extent_32_t
);
25 uint len64
= sizeof(xfs_efi_log_format_64_t
) + (nextents
- 1) * sizeof(xfs_extent_64_t
);
27 if (len
== dst_len
|| continued
) {
28 memcpy((char *)dst_efi_fmt
, buf
, len
);
30 } else if (len
== len32
) {
31 xfs_efi_log_format_32_t
*src_efi_fmt_32
= (xfs_efi_log_format_32_t
*)buf
;
33 dst_efi_fmt
->efi_type
= src_efi_fmt_32
->efi_type
;
34 dst_efi_fmt
->efi_size
= src_efi_fmt_32
->efi_size
;
35 dst_efi_fmt
->efi_nextents
= src_efi_fmt_32
->efi_nextents
;
36 dst_efi_fmt
->efi_id
= src_efi_fmt_32
->efi_id
;
37 for (i
= 0; i
< dst_efi_fmt
->efi_nextents
; i
++) {
38 dst_efi_fmt
->efi_extents
[i
].ext_start
=
39 src_efi_fmt_32
->efi_extents
[i
].ext_start
;
40 dst_efi_fmt
->efi_extents
[i
].ext_len
=
41 src_efi_fmt_32
->efi_extents
[i
].ext_len
;
44 } else if (len
== len64
) {
45 xfs_efi_log_format_64_t
*src_efi_fmt_64
= (xfs_efi_log_format_64_t
*)buf
;
47 dst_efi_fmt
->efi_type
= src_efi_fmt_64
->efi_type
;
48 dst_efi_fmt
->efi_size
= src_efi_fmt_64
->efi_size
;
49 dst_efi_fmt
->efi_nextents
= src_efi_fmt_64
->efi_nextents
;
50 dst_efi_fmt
->efi_id
= src_efi_fmt_64
->efi_id
;
51 for (i
= 0; i
< dst_efi_fmt
->efi_nextents
; i
++) {
52 dst_efi_fmt
->efi_extents
[i
].ext_start
=
53 src_efi_fmt_64
->efi_extents
[i
].ext_start
;
54 dst_efi_fmt
->efi_extents
[i
].ext_len
=
55 src_efi_fmt_64
->efi_extents
[i
].ext_len
;
59 fprintf(stderr
, _("%s: bad size of efi format: %u; expected %u or %u; nextents = %u\n"),
60 progname
, len
, len32
, len64
, nextents
);
70 xfs_efi_log_format_t
*src_f
, *f
= NULL
;
75 int core_size
= offsetof(xfs_efi_log_format_t
, efi_extents
);
78 * memmove to ensure 8-byte alignment for the long longs in
79 * xfs_efi_log_format_t structure
81 if ((src_f
= (xfs_efi_log_format_t
*)malloc(src_len
)) == NULL
) {
82 fprintf(stderr
, _("%s: xlog_print_trans_efi: malloc failed\n"), progname
);
85 memmove((char*)src_f
, *ptr
, src_len
);
88 /* convert to native format */
89 dst_len
= sizeof(xfs_efi_log_format_t
) + (src_f
->efi_nextents
- 1) * sizeof(xfs_extent_t
);
91 if (continued
&& src_len
< core_size
) {
92 printf(_("EFI: Not enough data to decode further\n"));
97 if ((f
= (xfs_efi_log_format_t
*)malloc(dst_len
)) == NULL
) {
98 fprintf(stderr
, _("%s: xlog_print_trans_efi: malloc failed\n"), progname
);
101 if (xfs_efi_copy_format((char*)src_f
, src_len
, f
, continued
)) {
106 printf(_("EFI: #regs: %d num_extents: %d id: 0x%llx\n"),
107 f
->efi_size
, f
->efi_nextents
, (unsigned long long)f
->efi_id
);
110 printf(_("EFI free extent data skipped (CONTINUE set, no space)\n"));
115 for (i
=0; i
< f
->efi_nextents
; i
++) {
116 printf("(s: 0x%llx, l: %d) ",
117 (unsigned long long)ex
->ext_start
, ex
->ext_len
);
118 if (i
% 4 == 3) printf("\n");
127 } /* xlog_print_trans_efi */
130 xlog_recover_print_efi(
131 xlog_recover_item_t
*item
)
133 xfs_efi_log_format_t
*f
, *src_f
;
136 uint src_len
, dst_len
;
138 src_f
= (xfs_efi_log_format_t
*)item
->ri_buf
[0].i_addr
;
139 src_len
= item
->ri_buf
[0].i_len
;
141 * An xfs_efi_log_format structure contains a variable length array
143 * Each element is of size xfs_extent_32_t or xfs_extent_64_t.
144 * Need to convert to native format.
146 dst_len
= sizeof(xfs_efi_log_format_t
) +
147 (src_f
->efi_nextents
- 1) * sizeof(xfs_extent_t
);
148 if ((f
= (xfs_efi_log_format_t
*)malloc(dst_len
)) == NULL
) {
149 fprintf(stderr
, _("%s: xlog_recover_print_efi: malloc failed\n"),
153 if (xfs_efi_copy_format((char*)src_f
, src_len
, f
, 0)) {
158 printf(_(" EFI: #regs:%d num_extents:%d id:0x%llx\n"),
159 f
->efi_size
, f
->efi_nextents
, (unsigned long long)f
->efi_id
);
162 for (i
=0; i
< f
->efi_nextents
; i
++) {
163 printf("(s: 0x%llx, l: %d) ",
164 (unsigned long long)ex
->ext_start
, ex
->ext_len
);
175 xlog_print_trans_efd(char **ptr
, uint len
)
177 xfs_efd_log_format_t
*f
;
178 xfs_efd_log_format_t lbuf
;
179 /* size without extents at end */
180 uint core_size
= sizeof(xfs_efd_log_format_t
) - sizeof(xfs_extent_t
);
183 * memmove to ensure 8-byte alignment for the long longs in
184 * xfs_efd_log_format_t structure
186 memmove(&lbuf
, *ptr
, min(core_size
, len
));
189 if (len
>= core_size
) {
190 printf(_("EFD: #regs: %d num_extents: %d id: 0x%llx\n"),
191 f
->efd_size
, f
->efd_nextents
,
192 (unsigned long long)f
->efd_efi_id
);
194 /* don't print extents as they are not used */
198 printf(_("EFD: Not enough data to decode further\n"));
201 } /* xlog_print_trans_efd */
204 xlog_recover_print_efd(
205 xlog_recover_item_t
*item
)
207 xfs_efd_log_format_t
*f
;
209 f
= (xfs_efd_log_format_t
*)item
->ri_buf
[0].i_addr
;
211 * An xfs_efd_log_format structure contains a variable length array
213 * Each element is of size xfs_extent_32_t or xfs_extent_64_t.
214 * However, the extents are never used and won't be printed.
216 printf(_(" EFD: #regs: %d num_extents: %d id: 0x%llx\n"),
217 f
->efd_size
, f
->efd_nextents
,
218 (unsigned long long)f
->efd_efi_id
);
221 /* Reverse Mapping Update Items */
227 struct xfs_rui_log_format
*dst_fmt
,
230 uint nextents
= ((struct xfs_rui_log_format
*)buf
)->rui_nextents
;
231 uint dst_len
= xfs_rui_log_format_sizeof(nextents
);
233 if (len
== dst_len
|| continued
) {
234 memcpy((char *)dst_fmt
, buf
, len
);
237 fprintf(stderr
, _("%s: bad size of RUI format: %u; expected %u; nextents = %u\n"),
238 progname
, len
, dst_len
, nextents
);
243 xlog_print_trans_rui(
248 struct xfs_rui_log_format
*src_f
, *f
= NULL
;
251 struct xfs_map_extent
*ex
;
256 core_size
= offsetof(struct xfs_rui_log_format
, rui_extents
);
259 * memmove to ensure 8-byte alignment for the long longs in
260 * struct xfs_rui_log_format structure
262 src_f
= malloc(src_len
);
264 fprintf(stderr
, _("%s: %s: malloc failed\n"),
268 memmove((char*)src_f
, *ptr
, src_len
);
271 /* convert to native format */
272 nextents
= src_f
->rui_nextents
;
273 dst_len
= xfs_rui_log_format_sizeof(nextents
);
275 if (continued
&& src_len
< core_size
) {
276 printf(_("RUI: Not enough data to decode further\n"));
283 fprintf(stderr
, _("%s: %s: malloc failed\n"),
287 if (xfs_rui_copy_format((char *)src_f
, src_len
, f
, continued
)) {
292 printf(_("RUI: #regs: %d num_extents: %d id: 0x%llx\n"),
293 f
->rui_size
, f
->rui_nextents
, (unsigned long long)f
->rui_id
);
296 printf(_("RUI extent data skipped (CONTINUE set, no space)\n"));
301 for (i
=0; i
< f
->rui_nextents
; i
++) {
302 printf("(s: 0x%llx, l: %d, own: %lld, off: %llu, f: 0x%x) ",
303 (unsigned long long)ex
->me_startblock
, ex
->me_len
,
304 (long long)ex
->me_owner
,
305 (unsigned long long)ex
->me_startoff
, ex
->me_flags
);
316 xlog_recover_print_rui(
317 struct xlog_recover_item
*item
)
322 src_f
= item
->ri_buf
[0].i_addr
;
323 src_len
= item
->ri_buf
[0].i_len
;
325 xlog_print_trans_rui(&src_f
, src_len
, 0);
329 xlog_print_trans_rud(
333 struct xfs_rud_log_format
*f
;
334 struct xfs_rud_log_format lbuf
;
336 /* size without extents at end */
337 uint core_size
= sizeof(struct xfs_rud_log_format
);
340 * memmove to ensure 8-byte alignment for the long longs in
341 * xfs_efd_log_format_t structure
343 memmove(&lbuf
, *ptr
, min(core_size
, len
));
346 if (len
>= core_size
) {
347 printf(_("RUD: #regs: %d id: 0x%llx\n"),
349 (unsigned long long)f
->rud_rui_id
);
351 /* don't print extents as they are not used */
355 printf(_("RUD: Not enough data to decode further\n"));
361 xlog_recover_print_rud(
362 struct xlog_recover_item
*item
)
366 f
= item
->ri_buf
[0].i_addr
;
367 xlog_print_trans_rud(&f
, sizeof(struct xfs_rud_log_format
));
370 /* Reference Count Update Items */
374 struct xfs_cui_log_format
*cui
,
376 struct xfs_cui_log_format
*dst_fmt
,
382 nextents
= cui
->cui_nextents
;
383 dst_len
= xfs_cui_log_format_sizeof(nextents
);
385 if (len
== dst_len
|| continued
) {
386 memcpy(dst_fmt
, cui
, len
);
389 fprintf(stderr
, _("%s: bad size of CUI format: %u; expected %u; nextents = %u\n"),
390 progname
, len
, dst_len
, nextents
);
395 xlog_print_trans_cui(
400 struct xfs_cui_log_format
*src_f
, *f
= NULL
;
403 struct xfs_phys_extent
*ex
;
408 core_size
= offsetof(struct xfs_cui_log_format
, cui_extents
);
410 src_f
= malloc(src_len
);
412 fprintf(stderr
, _("%s: %s: malloc failed\n"),
416 memcpy(src_f
, *ptr
, src_len
);
419 /* convert to native format */
420 nextents
= src_f
->cui_nextents
;
421 dst_len
= xfs_cui_log_format_sizeof(nextents
);
423 if (continued
&& src_len
< core_size
) {
424 printf(_("CUI: Not enough data to decode further\n"));
431 fprintf(stderr
, _("%s: %s: malloc failed\n"),
435 if (xfs_cui_copy_format(src_f
, src_len
, f
, continued
)) {
440 printf(_("CUI: #regs: %d num_extents: %d id: 0x%llx\n"),
441 f
->cui_size
, f
->cui_nextents
, (unsigned long long)f
->cui_id
);
444 printf(_("CUI extent data skipped (CONTINUE set, no space)\n"));
449 for (i
=0; i
< f
->cui_nextents
; i
++) {
450 printf("(s: 0x%llx, l: %d, f: 0x%x) ",
451 (unsigned long long)ex
->pe_startblock
, ex
->pe_len
,
463 xlog_recover_print_cui(
464 struct xlog_recover_item
*item
)
469 src_f
= item
->ri_buf
[0].i_addr
;
470 src_len
= item
->ri_buf
[0].i_len
;
472 xlog_print_trans_cui(&src_f
, src_len
, 0);
476 xlog_print_trans_cud(
480 struct xfs_cud_log_format
*f
;
481 struct xfs_cud_log_format lbuf
;
483 /* size without extents at end */
484 uint core_size
= sizeof(struct xfs_cud_log_format
);
486 memcpy(&lbuf
, *ptr
, min(core_size
, len
));
489 if (len
>= core_size
) {
490 printf(_("CUD: #regs: %d id: 0x%llx\n"),
492 (unsigned long long)f
->cud_cui_id
);
494 /* don't print extents as they are not used */
498 printf(_("CUD: Not enough data to decode further\n"));
504 xlog_recover_print_cud(
505 struct xlog_recover_item
*item
)
509 f
= item
->ri_buf
[0].i_addr
;
510 xlog_print_trans_cud(&f
, sizeof(struct xfs_cud_log_format
));
513 /* Block Mapping Update Items */
517 struct xfs_bui_log_format
*bui
,
519 struct xfs_bui_log_format
*dst_fmt
,
525 nextents
= bui
->bui_nextents
;
526 dst_len
= xfs_bui_log_format_sizeof(nextents
);
528 if (len
== dst_len
|| continued
) {
529 memcpy(dst_fmt
, bui
, len
);
532 fprintf(stderr
, _("%s: bad size of BUI format: %u; expected %u; nextents = %u\n"),
533 progname
, len
, dst_len
, nextents
);
538 xlog_print_trans_bui(
543 struct xfs_bui_log_format
*src_f
, *f
= NULL
;
546 struct xfs_map_extent
*ex
;
551 core_size
= offsetof(struct xfs_bui_log_format
, bui_extents
);
553 src_f
= malloc(src_len
);
555 fprintf(stderr
, _("%s: %s: malloc failed\n"),
559 memcpy(src_f
, *ptr
, src_len
);
562 /* convert to native format */
563 nextents
= src_f
->bui_nextents
;
564 dst_len
= xfs_bui_log_format_sizeof(nextents
);
566 if (continued
&& src_len
< core_size
) {
567 printf(_("BUI: Not enough data to decode further\n"));
574 fprintf(stderr
, _("%s: %s: malloc failed\n"),
578 if (xfs_bui_copy_format(src_f
, src_len
, f
, continued
)) {
583 printf(_("BUI: #regs: %d num_extents: %d id: 0x%llx\n"),
584 f
->bui_size
, f
->bui_nextents
, (unsigned long long)f
->bui_id
);
587 printf(_("BUI extent data skipped (CONTINUE set, no space)\n"));
592 for (i
=0; i
< f
->bui_nextents
; i
++) {
593 printf("(s: 0x%llx, l: %d, own: %lld, off: %llu, f: 0x%x) ",
594 (unsigned long long)ex
->me_startblock
, ex
->me_len
,
595 (long long)ex
->me_owner
,
596 (unsigned long long)ex
->me_startoff
, ex
->me_flags
);
607 xlog_recover_print_bui(
608 struct xlog_recover_item
*item
)
613 src_f
= item
->ri_buf
[0].i_addr
;
614 src_len
= item
->ri_buf
[0].i_len
;
616 xlog_print_trans_bui(&src_f
, src_len
, 0);
620 xlog_print_trans_bud(
624 struct xfs_bud_log_format
*f
;
625 struct xfs_bud_log_format lbuf
;
627 /* size without extents at end */
628 uint core_size
= sizeof(struct xfs_bud_log_format
);
630 memcpy(&lbuf
, *ptr
, min(core_size
, len
));
633 if (len
>= core_size
) {
634 printf(_("BUD: #regs: %d id: 0x%llx\n"),
636 (unsigned long long)f
->bud_bui_id
);
638 /* don't print extents as they are not used */
642 printf(_("BUD: Not enough data to decode further\n"));
648 xlog_recover_print_bud(
649 struct xlog_recover_item
*item
)
653 f
= item
->ri_buf
[0].i_addr
;
654 xlog_print_trans_bud(&f
, sizeof(struct xfs_bud_log_format
));