]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/log_misc.c
cmd/xfs/bmap/Makefile 1.8 Renamed to cmd/xfsprogs/bmap/Makefile
[thirdparty/xfsprogs-dev.git] / logprint / log_misc.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include "logprint.h"
34
35 #define ZEROED_LOG (-4)
36 #define FULL_READ (-3)
37 #define PARTIAL_READ (-2)
38 #define BAD_HEADER (-1)
39 #define NO_ERROR (0)
40
41 static int logBBsize;
42 char *trans_type[] = {
43 "",
44 "SETATTR",
45 "SETATTR_SIZE",
46 "INACTIVE",
47 "CREATE",
48 "CREATE_TRUNC",
49 "TRUNCATE_FILE",
50 "REMOVE",
51 "LINK",
52 "RENAME",
53 "MKDIR",
54 "RMDIR",
55 "SYMLINK",
56 "SET_DMATTRS",
57 "GROWFS",
58 "STRAT_WRITE",
59 "DIOSTRAT",
60 "WRITE_SYNC",
61 "WRITEID",
62 "ADDAFORK",
63 "ATTRINVAL",
64 "ATRUNCATE",
65 "ATTR_SET",
66 "ATTR_RM",
67 "ATTR_FLAG",
68 "CLEAR_AGI_BUCKET",
69 "QM_SBCHANGE",
70 "DUMMY1",
71 "DUMMY2",
72 "QM_QUOTAOFF",
73 "QM_DQALLOC",
74 "QM_SETQLIM",
75 "QM_DQCLUSTER",
76 "QM_QINOCREATE",
77 "QM_QUOTAOFF_END",
78 "SB_UNIT",
79 "FSYNC_TS",
80 "GROWFSRT_ALLOC",
81 "GROWFSRT_ZERO",
82 "GROWFSRT_FREE",
83 "SWAPEXT",
84 };
85
86 typedef struct xlog_split_item {
87 struct xlog_split_item *si_next;
88 struct xlog_split_item *si_prev;
89 xlog_tid_t si_tid;
90 int si_skip;
91 } xlog_split_item_t;
92
93 xlog_split_item_t *split_list = 0;
94
95 void
96 print_xlog_op_line(void)
97 {
98 printf("--------------------------------------"
99 "--------------------------------------\n");
100 } /* print_xlog_op_line */
101
102 void
103 print_xlog_record_line(void)
104 {
105 printf("======================================"
106 "======================================\n");
107 } /* print_xlog_record_line */
108
109 void
110 print_stars(void)
111 {
112 printf("***********************************"
113 "***********************************\n");
114 } /* print_xlog_record_line */
115
116 /*
117 * Given a pointer to a data segment, print out the data as if it were
118 * a log operation header.
119 */
120 void
121 xlog_print_op_header(xlog_op_header_t *op_head,
122 int i,
123 xfs_caddr_t *ptr)
124 {
125 xlog_op_header_t hbuf;
126
127 /*
128 * bcopy because on 64/n32, partial reads can cause the op_head
129 * pointer to come in pointing to an odd-numbered byte
130 */
131 bcopy(op_head, &hbuf, sizeof(xlog_op_header_t));
132 op_head = &hbuf;
133 *ptr += sizeof(xlog_op_header_t);
134 printf("Oper (%d): tid: %x len: %d clientid: %s ", i,
135 INT_GET(op_head->oh_tid, ARCH_CONVERT),
136 INT_GET(op_head->oh_len, ARCH_CONVERT),
137 (op_head->oh_clientid == XFS_TRANSACTION ? "TRANS" :
138 (op_head->oh_clientid == XFS_LOG ? "LOG" : "ERROR")));
139 printf("flags: ");
140 if (op_head->oh_flags) {
141 if (op_head->oh_flags & XLOG_START_TRANS)
142 printf("START ");
143 if (op_head->oh_flags & XLOG_COMMIT_TRANS)
144 printf("COMMIT ");
145 if (op_head->oh_flags & XLOG_WAS_CONT_TRANS)
146 printf("WAS_CONT ");
147 if (op_head->oh_flags & XLOG_UNMOUNT_TRANS)
148 printf("UNMOUNT ");
149 if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
150 printf("CONTINUE ");
151 if (op_head->oh_flags & XLOG_END_TRANS)
152 printf("END ");
153 } else {
154 printf("none");
155 }
156 printf("\n");
157 } /* xlog_print_op_header */
158
159
160 void
161 xlog_print_add_to_trans(xlog_tid_t tid,
162 int skip)
163 {
164 xlog_split_item_t *item;
165
166 item = (xlog_split_item_t *)calloc(sizeof(xlog_split_item_t), 1);
167 item->si_tid = tid;
168 item->si_skip = skip;
169 item->si_next = split_list;
170 item->si_prev = 0;
171 if (split_list)
172 split_list->si_prev = item;
173 split_list = item;
174 } /* xlog_print_add_to_trans */
175
176
177 int
178 xlog_print_find_tid(xlog_tid_t tid, uint was_cont)
179 {
180 xlog_split_item_t *listp = split_list;
181
182 if (!split_list) {
183 if (was_cont != 0) /* Not first time we have used this tid */
184 return 1;
185 else
186 return 0;
187 }
188 while (listp) {
189 if (listp->si_tid == tid)
190 break;
191 listp = listp->si_next;
192 }
193 if (!listp) {
194 return 0;
195 }
196 if (--listp->si_skip == 0) {
197 if (listp == split_list) { /* delete at head */
198 split_list = listp->si_next;
199 if (split_list)
200 split_list->si_prev = NULL;
201 } else {
202 if (listp->si_next)
203 listp->si_next->si_prev = listp->si_prev;
204 listp->si_prev->si_next = listp->si_next;
205 }
206 free(listp);
207 }
208 return 1;
209 } /* xlog_print_find_tid */
210
211 int
212 xlog_print_trans_header(xfs_caddr_t *ptr, int len)
213 {
214 xfs_trans_header_t *h;
215 xfs_caddr_t cptr = *ptr;
216 __uint32_t magic;
217 char *magic_c = (char *)&magic;
218
219 *ptr += len;
220
221 magic=*(__uint32_t*)cptr; /* XXX INT_GET soon */
222
223 if (len >= 4)
224 printf("%c%c%c%c:",
225 #if __BYTE_ORDER == __LITTLE_ENDIAN
226 magic_c[3], magic_c[2], magic_c[1], magic_c[0]);
227 #else
228 magic_c[0], magic_c[1], magic_c[2], magic_c[3]);
229 #endif
230 if (len != sizeof(xfs_trans_header_t)) {
231 printf(" Not enough data to decode further\n");
232 return 1;
233 }
234 h = (xfs_trans_header_t *)cptr;
235 printf(" type: %s tid: %x num_items: %d\n",
236 trans_type[h->th_type], h->th_tid, h->th_num_items);
237 return 0;
238 } /* xlog_print_trans_header */
239
240
241 int
242 xlog_print_trans_buffer(xfs_caddr_t *ptr, int len, int *i, int num_ops)
243 {
244 xfs_buf_log_format_t *f;
245 xfs_buf_log_format_v1_t *old_f;
246 xfs_agi_t *agi;
247 xfs_agf_t *agf;
248 xfs_disk_dquot_t *dq;
249 xlog_op_header_t *head = 0;
250 int num, skip;
251 int super_block = 0;
252 int bucket, col, buckets;
253 __int64_t blkno;
254 xfs_buf_log_format_t lbuf;
255 int size, blen, map_size, struct_size;
256 long long x, y;
257
258 /*
259 * bcopy to ensure 8-byte alignment for the long longs in
260 * buf_log_format_t structure
261 */
262 bcopy(*ptr, &lbuf, sizeof(xfs_buf_log_format_t));
263 f = &lbuf;
264 *ptr += len;
265
266 if (f->blf_type == XFS_LI_BUF) {
267 blkno = f->blf_blkno;
268 size = f->blf_size;
269 blen = f->blf_len;
270 map_size = f->blf_map_size;
271 struct_size = sizeof(xfs_buf_log_format_t);
272 } else {
273 old_f = (xfs_buf_log_format_v1_t*)f;
274 blkno = old_f->blf_blkno;
275 size = old_f->blf_size;
276 blen = old_f->blf_len;
277 map_size = old_f->blf_map_size;
278 struct_size = sizeof(xfs_buf_log_format_v1_t);
279 }
280 switch (f->blf_type) {
281 case XFS_LI_BUF:
282 printf("BUF: ");
283 break;
284 case XFS_LI_6_1_BUF:
285 printf("6.1 BUF: ");
286 break;
287 case XFS_LI_5_3_BUF:
288 printf("5.3 BUF: ");
289 break;
290 case XFS_LI_DQUOT:
291 printf("DQUOT BUF: ");
292 break;
293 default:
294 printf("UNKNOWN BUF: ");
295 break;
296 }
297 if (len >= struct_size) {
298 ASSERT((len - sizeof(struct_size)) % sizeof(int) == 0);
299 printf("#regs: %d start blkno: %lld (0x%llx) len: %d bmap size: %d\n",
300 size, blkno, blkno, blen, map_size);
301 if (blkno == 0)
302 super_block = 1;
303 } else {
304 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
305 printf("#regs: %d Not printing rest of data\n", f->blf_size);
306 return size;
307 }
308 num = size-1;
309
310 /* Check if all regions in this log item were in the given LR ptr */
311 if (*i+num > num_ops-1) {
312 skip = num - (num_ops-1-*i);
313 num = num_ops-1-*i;
314 } else {
315 skip = 0;
316 }
317 while (num-- > 0) {
318 (*i)++;
319 head = (xlog_op_header_t *)*ptr;
320 xlog_print_op_header(head, *i, ptr);
321 if (super_block) {
322 printf("SUPER BLOCK Buffer: ");
323 if (INT_GET(head->oh_len, ARCH_CONVERT) < 4*8) {
324 printf("Out of space\n");
325 } else {
326 printf("\n");
327 /*
328 * bcopy because *ptr may not be 8-byte aligned
329 */
330 bcopy(*ptr, &x, sizeof(long long));
331 bcopy(*ptr+8, &y, sizeof(long long));
332 printf("icount: %lld ifree: %lld ",
333 INT_GET(x, ARCH_CONVERT),
334 INT_GET(y, ARCH_CONVERT));
335 bcopy(*ptr+16, &x, sizeof(long long));
336 bcopy(*ptr+24, &y, sizeof(long long));
337 printf("fdblks: %lld frext: %lld\n",
338 INT_GET(x, ARCH_CONVERT),
339 INT_GET(y, ARCH_CONVERT));
340 }
341 super_block = 0;
342 } else if (INT_GET(*(uint *)(*ptr), ARCH_CONVERT) == XFS_AGI_MAGIC) {
343 agi = (xfs_agi_t *)(*ptr);
344 printf("AGI Buffer: XAGI ");
345 if (INT_GET(head->oh_len, ARCH_CONVERT) <
346 sizeof(xfs_agi_t) -
347 XFS_AGI_UNLINKED_BUCKETS*sizeof(xfs_agino_t)) {
348 printf("out of space\n");
349 } else {
350 printf("\n");
351 printf("ver: %d ",
352 INT_GET(agi->agi_versionnum, ARCH_CONVERT));
353 printf("seq#: %d len: %d cnt: %d root: %d\n",
354 INT_GET(agi->agi_seqno, ARCH_CONVERT),
355 INT_GET(agi->agi_length, ARCH_CONVERT),
356 INT_GET(agi->agi_count, ARCH_CONVERT),
357 INT_GET(agi->agi_root, ARCH_CONVERT));
358 printf("level: %d free#: 0x%x newino: 0x%x\n",
359 INT_GET(agi->agi_level, ARCH_CONVERT),
360 INT_GET(agi->agi_freecount, ARCH_CONVERT),
361 INT_GET(agi->agi_newino, ARCH_CONVERT));
362 if (INT_GET(head->oh_len, ARCH_CONVERT) == 128) {
363 buckets = 17;
364 } else if (INT_GET(head->oh_len, ARCH_CONVERT) == 256) {
365 buckets = 32 + 17;
366 } else {
367 buckets = XFS_AGI_UNLINKED_BUCKETS;
368 }
369 for (bucket = 0; bucket < buckets;) {
370 printf("bucket[%d - %d]: ", bucket, bucket+3);
371 for (col = 0; col < 4; col++, bucket++) {
372 if (bucket < buckets) {
373 printf("0x%x ",
374 INT_GET(agi->agi_unlinked[bucket], ARCH_CONVERT));
375 }
376 }
377 printf("\n");
378 }
379 }
380 } else if (INT_GET(*(uint *)(*ptr), ARCH_CONVERT) == XFS_AGF_MAGIC) {
381 agf = (xfs_agf_t *)(*ptr);
382 printf("AGF Buffer: XAGF ");
383 if (INT_GET(head->oh_len, ARCH_CONVERT) < sizeof(xfs_agf_t)) {
384 printf("Out of space\n");
385 } else {
386 printf("\n");
387 printf("ver: %d seq#: %d len: %d \n",
388 INT_GET(agf->agf_versionnum, ARCH_CONVERT),
389 INT_GET(agf->agf_seqno, ARCH_CONVERT),
390 INT_GET(agf->agf_length, ARCH_CONVERT));
391 printf("root BNO: %d CNT: %d\n",
392 INT_GET(agf->agf_roots[XFS_BTNUM_BNOi],
393 ARCH_CONVERT),
394 INT_GET(agf->agf_roots[XFS_BTNUM_CNTi],
395 ARCH_CONVERT));
396 printf("level BNO: %d CNT: %d\n",
397 INT_GET(agf->agf_levels[XFS_BTNUM_BNOi],
398 ARCH_CONVERT),
399 INT_GET(agf->agf_levels[XFS_BTNUM_CNTi],
400 ARCH_CONVERT));
401 printf("1st: %d last: %d cnt: %d "
402 "freeblks: %d longest: %d\n",
403 INT_GET(agf->agf_flfirst, ARCH_CONVERT),
404 INT_GET(agf->agf_fllast, ARCH_CONVERT),
405 INT_GET(agf->agf_flcount, ARCH_CONVERT),
406 INT_GET(agf->agf_freeblks, ARCH_CONVERT),
407 INT_GET(agf->agf_longest, ARCH_CONVERT));
408 }
409 } else if (INT_GET(*(uint *)(*ptr), ARCH_CONVERT) == XFS_DQUOT_MAGIC) {
410 dq = (xfs_disk_dquot_t *)(*ptr);
411 printf("DQUOT Buffer: DQ ");
412 if (INT_GET(head->oh_len, ARCH_CONVERT) <
413 sizeof(xfs_disk_dquot_t)) {
414 printf("Out of space\n");
415 }
416 else {
417 printf("\n");
418 printf("ver: %d flags: 0x%x id: %d \n",
419 INT_GET(dq->d_version, ARCH_CONVERT),
420 INT_GET(dq->d_flags, ARCH_CONVERT),
421 INT_GET(dq->d_id, ARCH_CONVERT));
422 printf("blk limits hard: %llu soft: %llu\n",
423 INT_GET(dq->d_blk_hardlimit, ARCH_CONVERT),
424 INT_GET(dq->d_blk_softlimit, ARCH_CONVERT));
425 printf("blk count: %llu warns: %d timer: %d\n",
426 INT_GET(dq->d_bcount, ARCH_CONVERT),
427 INT_GET(dq->d_bwarns, ARCH_CONVERT),
428 INT_GET(dq->d_btimer, ARCH_CONVERT));
429 printf("ino limits hard: %llu soft: %llu\n",
430 INT_GET(dq->d_ino_hardlimit, ARCH_CONVERT),
431 INT_GET(dq->d_ino_softlimit, ARCH_CONVERT));
432 printf("ino count: %llu warns: %d timer: %d\n",
433 INT_GET(dq->d_icount, ARCH_CONVERT),
434 INT_GET(dq->d_iwarns, ARCH_CONVERT),
435 INT_GET(dq->d_itimer, ARCH_CONVERT));
436 }
437 } else {
438 printf("BUF DATA\n");
439 if (print_data) {
440 uint *dp = (uint *)*ptr;
441 int nums = INT_GET(head->oh_len, ARCH_CONVERT) >> 2;
442 int i = 0;
443
444 while (i < nums) {
445 if ((i % 8) == 0)
446 printf("%2x ", i);
447 printf("%8x ", *dp);
448 dp++;
449 i++;
450 if ((i % 8) == 0)
451 printf("\n");
452 }
453 printf("\n");
454 }
455 }
456 *ptr += INT_GET(head->oh_len, ARCH_CONVERT);
457 }
458 if (head && head->oh_flags & XLOG_CONTINUE_TRANS)
459 skip++;
460 return skip;
461 } /* xlog_print_trans_buffer */
462
463
464 int
465 xlog_print_trans_efd(xfs_caddr_t *ptr, uint len)
466 {
467 xfs_efd_log_format_t *f;
468 xfs_extent_t *ex;
469 int i;
470 xfs_efd_log_format_t lbuf;
471
472 /*
473 * bcopy to ensure 8-byte alignment for the long longs in
474 * xfs_efd_log_format_t structure
475 */
476 bcopy(*ptr, &lbuf, sizeof(xfs_efd_log_format_t));
477 f = &lbuf;
478 *ptr += len;
479 if (len >= sizeof(xfs_efd_log_format_t)) {
480 printf("EFD: #regs: %d num_extents: %d id: 0x%llx\n",
481 f->efd_size, f->efd_nextents, f->efd_efi_id);
482 ex = f->efd_extents;
483 for (i=0; i< f->efd_size; i++) {
484 printf("(s: 0x%llx, l: %d) ", ex->ext_start, ex->ext_len);
485 if (i % 4 == 3) printf("\n");
486 ex++;
487 }
488 if (i % 4 != 0) printf("\n");
489 return 0;
490 } else {
491 printf("EFD: Not enough data to decode further\n");
492 return 1;
493 }
494 } /* xlog_print_trans_efd */
495
496
497 int
498 xlog_print_trans_efi(xfs_caddr_t *ptr, uint len)
499 {
500 xfs_efi_log_format_t *f;
501 xfs_extent_t *ex;
502 int i;
503 xfs_efi_log_format_t lbuf;
504
505 /*
506 * bcopy to ensure 8-byte alignment for the long longs in
507 * xfs_efi_log_format_t structure
508 */
509 bcopy(*ptr, &lbuf, sizeof(xfs_efi_log_format_t));
510 f = &lbuf;
511 *ptr += len;
512 if (len >= sizeof(xfs_efi_log_format_t)) {
513 printf("EFI: #regs: %d num_extents: %d id: 0x%llx\n",
514 f->efi_size, f->efi_nextents, f->efi_id);
515 ex = f->efi_extents;
516 for (i=0; i< f->efi_size; i++) {
517 printf("(s: 0x%llx, l: %d) ", ex->ext_start, ex->ext_len);
518 if (i % 4 == 3) printf("\n");
519 ex++;
520 }
521 if (i % 4 != 0) printf("\n");
522 return 0;
523 } else {
524 printf("EFI: Not enough data to decode further\n");
525 return 1;
526 }
527 } /* xlog_print_trans_efi */
528
529
530 /* ARGSUSED */
531 void
532 xlog_print_trans_inode_core(xfs_dinode_core_t *ip)
533 {
534 printf("INODE CORE\n");
535 printf("magic 0x%hx mode 0%ho version %d format %d\n",
536 ip->di_magic, ip->di_mode, (int)ip->di_version,
537 (int)ip->di_format);
538 printf("nlink %hd uid %d gid %d\n",
539 ip->di_nlink, ip->di_uid, ip->di_gid);
540 printf("atime 0x%x mtime 0x%x ctime 0x%x\n",
541 ip->di_atime.t_sec, ip->di_mtime.t_sec, ip->di_ctime.t_sec);
542 printf("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%x\n",
543 ip->di_size, ip->di_nblocks, ip->di_extsize, ip->di_nextents);
544 printf("naextents 0x%x forkoff %d dmevmask 0x%x dmstate 0x%hx\n",
545 ip->di_anextents, (int)ip->di_forkoff, ip->di_dmevmask,
546 ip->di_dmstate);
547 printf("flags 0x%x gen 0x%x\n",
548 ip->di_flags, ip->di_gen);
549 }
550
551 void
552 xlog_print_dir_sf(xfs_dir_shortform_t *sfp, int size)
553 {
554 xfs_ino_t ino;
555 int count;
556 int i;
557 char namebuf[257];
558 xfs_dir_sf_entry_t *sfep;
559
560 /* XXX need to determine whether this is v1 or v2, then
561 print appropriate structure */
562
563 printf("SHORTFORM DIRECTORY size %d\n",
564 size);
565 /* bail out for now */
566
567 return;
568
569 printf("SHORTFORM DIRECTORY size %d count %d\n",
570 size, sfp->hdr.count);
571 bcopy(&(sfp->hdr.parent), &ino, sizeof(ino));
572 printf(".. ino 0x%llx\n", INT_GET(ino, ARCH_CONVERT));
573
574 count = (uint)(sfp->hdr.count);
575 sfep = &(sfp->list[0]);
576 for (i = 0; i < count; i++) {
577 bcopy(&(sfep->inumber), &ino, sizeof(ino));
578 bcopy((sfep->name), namebuf, sfep->namelen);
579 namebuf[sfep->namelen] = '\0';
580 printf("%s ino 0x%llx namelen %d\n",
581 namebuf, ino, sfep->namelen);
582 sfep = XFS_DIR_SF_NEXTENTRY(sfep);
583 }
584 }
585
586 int
587 xlog_print_trans_inode(xfs_caddr_t *ptr, int len, int *i, int num_ops)
588 {
589 xfs_inode_log_format_t *f;
590 xfs_inode_log_format_t_v1 *old_f;
591 xfs_dinode_core_t dino;
592 xlog_op_header_t *op_head;
593 int version;
594 xfs_inode_log_format_t lbuf = {0};
595 int mode;
596 int size;
597
598 /*
599 * print inode type header region
600 *
601 * bcopy to ensure 8-byte alignment for the long longs in
602 * xfs_inode_log_format_t structure
603 *
604 * len can be smaller than xfs_inode_log_format_t sometimes... (?)
605 */
606 bcopy(*ptr, &lbuf, MIN(sizeof(xfs_inode_log_format_t), len));
607 version = lbuf.ilf_type;
608 f = &lbuf;
609 (*i)++; /* bump index */
610 *ptr += len;
611 if (version == XFS_LI_5_3_INODE) {
612 old_f = (xfs_inode_log_format_t_v1 *)f;
613 if (len == sizeof(xfs_inode_log_format_t_v1)) {
614 printf("5.3 INODE: #regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n",
615 old_f->ilf_size, old_f->ilf_ino,
616 old_f->ilf_fields, old_f->ilf_dsize);
617 } else {
618 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
619 printf("5.3 INODE: #regs: %d Not printing rest of data\n",
620 old_f->ilf_size);
621 return old_f->ilf_size;
622 }
623 } else {
624 if (len == sizeof(xfs_inode_log_format_t)) {
625 if (version == XFS_LI_6_1_INODE)
626 printf("6.1 INODE: ");
627 else printf("INODE: ");
628 printf("#regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n",
629 f->ilf_size, f->ilf_ino, f->ilf_fields, f->ilf_dsize);
630 printf(" blkno: %lld len: %d boff: %d\n",
631 f->ilf_blkno, f->ilf_len, f->ilf_boffset);
632 } else {
633 ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
634 printf("INODE: #regs: %d Not printing rest of data\n",
635 f->ilf_size);
636 return f->ilf_size;
637 }
638 }
639
640 if (*i >= num_ops) /* end of LR */
641 return f->ilf_size-1;
642
643 /* core inode comes 2nd */
644 op_head = (xlog_op_header_t *)*ptr;
645 xlog_print_op_header(op_head, *i, ptr);
646
647 if (XLOG_SET(op_head->oh_flags, XLOG_CONTINUE_TRANS)) {
648 return f->ilf_size-1;
649 }
650
651 bcopy(*ptr, &dino, sizeof(dino));
652 mode = dino.di_mode & IFMT;
653 size = (int)dino.di_size;
654 xlog_print_trans_inode_core(&dino);
655 *ptr += sizeof(xfs_dinode_core_t);
656
657 if (*i == num_ops-1 && f->ilf_size == 3) {
658 return 1;
659 }
660
661 /* does anything come next */
662 op_head = (xlog_op_header_t *)*ptr;
663 switch (f->ilf_fields & XFS_ILOG_NONCORE) {
664 case XFS_ILOG_DEXT: {
665 ASSERT(f->ilf_size == 3);
666 (*i)++;
667 xlog_print_op_header(op_head, *i, ptr);
668 printf("EXTENTS inode data\n");
669 *ptr += INT_GET(op_head->oh_len, ARCH_CONVERT);
670 if (XLOG_SET(op_head->oh_flags, XLOG_CONTINUE_TRANS)) {
671 return 1;
672 }
673 break;
674 }
675 case XFS_ILOG_DBROOT: {
676 ASSERT(f->ilf_size == 3);
677 (*i)++;
678 xlog_print_op_header(op_head, *i, ptr);
679 printf("BTREE inode data\n");
680 *ptr += INT_GET(op_head->oh_len, ARCH_CONVERT);
681 if (XLOG_SET(op_head->oh_flags, XLOG_CONTINUE_TRANS)) {
682 return 1;
683 }
684 break;
685 }
686 case XFS_ILOG_DDATA: {
687 ASSERT(f->ilf_size == 3);
688 (*i)++;
689 xlog_print_op_header(op_head, *i, ptr);
690 printf("LOCAL inode data\n");
691 if (mode == IFDIR) {
692 xlog_print_dir_sf((xfs_dir_shortform_t*)*ptr, size);
693 }
694 *ptr += INT_GET(op_head->oh_len, ARCH_CONVERT);
695 if (XLOG_SET(op_head->oh_flags, XLOG_CONTINUE_TRANS))
696 return 1;
697 break;
698 }
699 case XFS_ILOG_DEV: {
700 ASSERT(f->ilf_size == 2);
701 printf("DEV inode: no extra region\n");
702 break;
703 }
704 case XFS_ILOG_UUID: {
705 ASSERT(f->ilf_size == 2);
706 printf("UUID inode: no extra region\n");
707 break;
708 }
709 case 0: {
710 ASSERT(f->ilf_size == 2);
711 break;
712 }
713 default: {
714 xlog_panic("xlog_print_trans_inode: illegal inode type");
715 }
716 }
717 return 0;
718 } /* xlog_print_trans_inode */
719
720
721
722 /******************************************************************************
723 *
724 * Log print routines
725 *
726 ******************************************************************************
727 */
728
729 void
730 xlog_print_lseek(xlog_t *log, int fd, xfs_daddr_t blkno, int whence)
731 {
732 #define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
733 xfs_off_t offset;
734
735 if (whence == SEEK_SET)
736 offset = BBTOOFF64(blkno+log->l_logBBstart);
737 else
738 offset = BBTOOFF64(blkno);
739 if (lseek64(fd, offset, whence) < 0) {
740 fprintf(stderr, "%s: lseek64 to %llu failed: %s\n",
741 progname, offset, strerror(errno));
742 exit(1);
743 }
744 } /* xlog_print_lseek */
745
746
747 void
748 print_lsn(xfs_caddr_t string,
749 xfs_lsn_t *lsn,
750 xfs_arch_t arch)
751 {
752 printf("%s: %u,%u", string,
753 CYCLE_LSN(*lsn, arch), BLOCK_LSN(*lsn, arch));
754 }
755
756
757 int
758 xlog_print_record(int fd,
759 int num_ops,
760 int len,
761 int *read_type,
762 xfs_caddr_t *partial_buf,
763 xlog_rec_header_t *rhead)
764 {
765 xlog_op_header_t *op_head;
766 xlog_rec_header_t *rechead;
767 xfs_caddr_t buf, ptr;
768 int read_len, skip;
769 int ret, n, i;
770
771 if (print_no_print)
772 return NO_ERROR;
773
774 if (!len) {
775 printf("\n");
776 return NO_ERROR;
777 }
778
779 /* read_len must read up to some block boundary */
780 read_len = (int) BBTOB(BTOBB(len));
781
782 /* read_type => don't malloc() new buffer, use old one */
783 if (*read_type == FULL_READ) {
784 if ((ptr = buf = (xfs_caddr_t)malloc(read_len)) == NULL) {
785 fprintf(stderr, "xlog_print_record: malloc failed\n");
786 exit(1);
787 }
788 } else {
789 read_len -= *read_type;
790 buf = (xfs_caddr_t)((__psint_t)(*partial_buf) + (__psint_t)(*read_type));
791 ptr = *partial_buf;
792 }
793 if ((ret = (int) read(fd, buf, read_len)) == -1) {
794 fprintf(stderr, "xlog_print_record: read error\n");
795 exit(1);
796 }
797 /* Did we overflow the end? */
798 if (*read_type == FULL_READ &&
799 BLOCK_LSN(rhead->h_lsn, ARCH_CONVERT)+BTOBB(read_len) >= logBBsize) {
800 *read_type = BBTOB(logBBsize-BLOCK_LSN(rhead->h_lsn, ARCH_CONVERT)-1);
801 *partial_buf = buf;
802 return PARTIAL_READ;
803 }
804
805 /* Did we read everything? */
806 if ((ret == 0 && read_len != 0) || ret != read_len) {
807 *read_type = ret;
808 *partial_buf = buf;
809 return PARTIAL_READ;
810 }
811 if (*read_type != FULL_READ)
812 read_len += *read_type;
813
814 /* Everything read in. Start from beginning of buffer */
815 buf = ptr;
816 for (i = 0; ptr < buf + read_len; ptr += BBSIZE, i++) {
817 rechead = (xlog_rec_header_t *)ptr;
818 if (INT_GET(rechead->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM) {
819 xlog_print_lseek(0, fd, -read_len+i*BBSIZE, SEEK_CUR);
820 free(buf);
821 return -1;
822 } else {
823 if (INT_GET(rhead->h_cycle, ARCH_CONVERT) !=
824 INT_GET(*(uint *)ptr, ARCH_CONVERT)) {
825 if (*read_type == FULL_READ)
826 return -1;
827 else if (INT_GET(rhead->h_cycle, ARCH_CONVERT) + 1 !=
828 INT_GET(*(uint *)ptr, ARCH_CONVERT))
829 return -1;
830 }
831 }
832 INT_SET(*(uint *)ptr, ARCH_CONVERT,
833 INT_GET(rhead->h_cycle_data[i], ARCH_CONVERT));
834 }
835 ptr = buf;
836 for (i=0; i<num_ops; i++) {
837 print_xlog_op_line();
838 op_head = (xlog_op_header_t *)ptr;
839 xlog_print_op_header(op_head, i, &ptr);
840
841 /* print transaction data */
842 if (print_no_data ||
843 ((XLOG_SET(op_head->oh_flags, XLOG_WAS_CONT_TRANS) ||
844 XLOG_SET(op_head->oh_flags, XLOG_CONTINUE_TRANS)) &&
845 INT_GET(op_head->oh_len, ARCH_CONVERT) == 0)) {
846 for (n = 0; n < INT_GET(op_head->oh_len, ARCH_CONVERT); n++) {
847 printf("%c", *ptr);
848 ptr++;
849 }
850 printf("\n");
851 continue;
852 }
853 if (xlog_print_find_tid(INT_GET(op_head->oh_tid, ARCH_CONVERT),
854 op_head->oh_flags & XLOG_WAS_CONT_TRANS)) {
855 printf("Left over region from split log item\n");
856 ptr += INT_GET(op_head->oh_len, ARCH_CONVERT);
857 continue;
858 }
859 if (INT_GET(op_head->oh_len, ARCH_CONVERT) != 0) {
860 if (*(uint *)ptr == XFS_TRANS_HEADER_MAGIC) {
861 skip = xlog_print_trans_header(&ptr,
862 INT_GET(op_head->oh_len, ARCH_CONVERT));
863 } else {
864 switch (*(unsigned short *)ptr) {
865 case XFS_LI_5_3_BUF:
866 case XFS_LI_6_1_BUF:
867 case XFS_LI_DQUOT:
868 case XFS_LI_BUF: {
869 skip = xlog_print_trans_buffer(&ptr,
870 INT_GET(op_head->oh_len, ARCH_CONVERT),
871 &i, num_ops);
872 break;
873 }
874 case XFS_LI_5_3_INODE:
875 case XFS_LI_6_1_INODE:
876 case XFS_LI_INODE: {
877 skip = xlog_print_trans_inode(&ptr,
878 INT_GET(op_head->oh_len, ARCH_CONVERT),
879 &i, num_ops);
880 break;
881 }
882 case XFS_LI_EFI: {
883 skip = xlog_print_trans_efi(&ptr,
884 INT_GET(op_head->oh_len, ARCH_CONVERT));
885 break;
886 }
887 case XFS_LI_EFD: {
888 skip = xlog_print_trans_efd(&ptr,
889 INT_GET(op_head->oh_len, ARCH_CONVERT));
890 break;
891 }
892 case XLOG_UNMOUNT_TYPE: {
893 printf("Unmount filesystem\n");
894 skip = 0;
895 break;
896 }
897 default: {
898 fprintf(stderr, "%s: unknown log operation type (%x)\n",
899 progname, *(unsigned short *)ptr);
900 skip = 0;
901 ptr += INT_GET(op_head->oh_len, ARCH_CONVERT);
902 }
903 } /* switch */
904 } /* else */
905 if (skip != 0)
906 xlog_print_add_to_trans(INT_GET(op_head->oh_tid, ARCH_CONVERT), skip);
907 }
908 }
909 printf("\n");
910 free(buf);
911 return NO_ERROR;
912 } /* xlog_print_record */
913
914
915 int
916 xlog_print_rec_head(xlog_rec_header_t *head, int *len)
917 {
918 int i;
919 char uub[64];
920 int datalen,bbs;
921
922 if (print_no_print)
923 return INT_GET(head->h_num_logops, ARCH_CONVERT);
924
925 if (INT_ISZERO(head->h_magicno, ARCH_CONVERT))
926 return ZEROED_LOG;
927
928 if (INT_GET(head->h_magicno, ARCH_CONVERT) != XLOG_HEADER_MAGIC_NUM) {
929 printf("Header 0x%x wanted 0x%x\n",
930 INT_GET(head->h_magicno, ARCH_CONVERT),
931 XLOG_HEADER_MAGIC_NUM);
932 return BAD_HEADER;
933 }
934
935 datalen=INT_GET(head->h_len, ARCH_CONVERT);
936 bbs=(datalen/BBSIZE)+(datalen%BBSIZE)?1:0;
937
938 printf("cycle: %d version: %d ",
939 INT_GET(head->h_cycle, ARCH_CONVERT),
940 INT_GET(head->h_version, ARCH_CONVERT));
941 print_lsn(" lsn", &head->h_lsn, ARCH_CONVERT);
942 print_lsn(" tail_lsn", &head->h_tail_lsn, ARCH_CONVERT);
943 printf("\n");
944 printf("length of Log Record: %d prev offset: %d num ops: %d\n",
945 datalen,
946 INT_GET(head->h_prev_block, ARCH_CONVERT),
947 INT_GET(head->h_num_logops, ARCH_CONVERT));
948
949 if (print_overwrite) {
950 printf("cycle num overwrites: ");
951 for (i=0; i< bbs; i++)
952 printf("%d - 0x%x ",
953 i,
954 INT_GET(head->h_cycle_data[i], ARCH_CONVERT));
955 printf("\n");
956 }
957
958 uuid_unparse(head->h_fs_uuid, uub);
959 printf("uuid: %s format: ", uub);
960 switch (INT_GET(head->h_fmt, ARCH_CONVERT)) {
961 case XLOG_FMT_UNKNOWN:
962 printf("unknown\n");
963 break;
964 case XLOG_FMT_LINUX_LE:
965 printf("little endian linux\n");
966 break;
967 case XLOG_FMT_LINUX_BE:
968 printf("big endian linux\n");
969 break;
970 case XLOG_FMT_IRIX_BE:
971 printf("big endian irix\n");
972 break;
973 default:
974 printf("? (%d)\n", INT_GET(head->h_fmt, ARCH_CONVERT));
975 break;
976 }
977
978 *len = INT_GET(head->h_len, ARCH_CONVERT);
979 return(INT_GET(head->h_num_logops, ARCH_CONVERT));
980 } /* xlog_print_rec_head */
981
982 static void
983 print_xlog_bad_zeroed(xfs_daddr_t blkno)
984 {
985 print_stars();
986 printf("* ERROR: found data after zeroed blocks block=%-21lld *\n",
987 (__int64_t)blkno);
988 print_stars();
989 if (print_exit)
990 xlog_exit("Bad log - data after zeroed blocks");
991 } /* print_xlog_bad_zeroed */
992
993 static void
994 print_xlog_bad_header(xfs_daddr_t blkno, xfs_caddr_t buf)
995 {
996 print_stars();
997 printf("* ERROR: header cycle=%-11d block=%-21lld *\n",
998 GET_CYCLE(buf, ARCH_CONVERT), (__int64_t)blkno);
999 print_stars();
1000 if (print_exit)
1001 xlog_exit("Bad log record header");
1002 } /* print_xlog_bad_header */
1003
1004 void
1005 print_xlog_bad_data(xfs_daddr_t blkno)
1006 {
1007 print_stars();
1008 printf("* ERROR: data block=%-21lld *\n",
1009 (__int64_t)blkno);
1010 print_stars();
1011 if (print_exit)
1012 xlog_exit("Bad data in log");
1013 } /* print_xlog_bad_data */
1014
1015
1016 /*
1017 * This code is gross and needs to be rewritten.
1018 */
1019 void xfs_log_print(xlog_t *log,
1020 int fd,
1021 int print_block_start)
1022 {
1023 char hbuf[XLOG_HEADER_SIZE];
1024 int num_ops, len;
1025 xfs_daddr_t block_end = 0, block_start, blkno, error;
1026 int read_type = FULL_READ;
1027 xfs_caddr_t partial_buf;
1028 int zeroed = 0;
1029
1030 logBBsize = log->l_logBBsize;
1031
1032 /*
1033 * Normally, block_start and block_end are the same value since we
1034 * are printing the entire log. However, if the start block is given,
1035 * we still end at the end of the logical log.
1036 */
1037 if (error = xlog_print_find_oldest(log, &block_end)) {
1038 fprintf(stderr, "%s: problem finding oldest LR\n", progname);
1039 return;
1040 }
1041 if (print_block_start == -1)
1042 block_start = block_end;
1043 else
1044 block_start = print_block_start;
1045 xlog_print_lseek(log, fd, block_start, SEEK_SET);
1046 blkno = block_start;
1047
1048 for (;;) {
1049 if (read(fd, hbuf, 512) == 0) {
1050 printf("%s: physical end of log\n", progname);
1051 print_xlog_record_line();
1052 break;
1053 }
1054 if (print_only_data) {
1055 printf("BLKNO: %lld\n", (__int64_t)blkno);
1056 xlog_recover_print_data(hbuf, 512);
1057 blkno++;
1058 goto loop;
1059 }
1060 num_ops = xlog_print_rec_head((xlog_rec_header_t *)hbuf, &len);
1061 blkno++;
1062
1063 if (zeroed && num_ops != ZEROED_LOG) {
1064 printf("%s: after %d zeroed blocks\n", progname, zeroed);
1065 /* once we find zeroed blocks - that's all we expect */
1066 print_xlog_bad_zeroed(blkno-1);
1067 /* reset count since we're assuming previous zeroed blocks
1068 * were bad
1069 */
1070 zeroed = 0;
1071 }
1072
1073 if (num_ops == ZEROED_LOG || num_ops == BAD_HEADER) {
1074 if (num_ops == ZEROED_LOG) {
1075 zeroed++;
1076 } else {
1077 print_xlog_bad_header(blkno-1, hbuf);
1078 }
1079
1080 goto loop;
1081 }
1082
1083 error = xlog_print_record(fd, num_ops, len, &read_type, &partial_buf,
1084 (xlog_rec_header_t *)hbuf);
1085 switch (error) {
1086 case 0: {
1087 blkno += BTOBB(len);
1088 if (print_block_start != -1 &&
1089 blkno >= block_end) /* If start specified, we */
1090 goto end; /* end early */
1091 break;
1092 }
1093 case -1: {
1094 print_xlog_bad_data(blkno-1);
1095 if (print_block_start != -1 &&
1096 blkno >= block_end) /* If start specified, */
1097 goto end; /* we end early */
1098 xlog_print_lseek(log, fd, blkno, SEEK_SET);
1099 goto loop;
1100 }
1101 case PARTIAL_READ: {
1102 print_xlog_record_line();
1103 printf("%s: physical end of log\n", progname);
1104 print_xlog_record_line();
1105 blkno = 0;
1106 xlog_print_lseek(log, fd, 0, SEEK_SET);
1107 /*
1108 * We may have hit the end of the log when we started at 0.
1109 * In this case, just end.
1110 */
1111 if (block_start == 0)
1112 goto end;
1113 goto partial_log_read;
1114 }
1115 default: xlog_panic("illegal value");
1116 }
1117 print_xlog_record_line();
1118 loop:
1119 if (blkno >= logBBsize) {
1120 if (zeroed) {
1121 printf("%s: skipped %d zeroed blocks\n", progname, zeroed);
1122 if (zeroed == logBBsize)
1123 printf("%s: totally zeroed log\n", progname);
1124
1125 zeroed=0;
1126 }
1127 printf("%s: physical end of log\n", progname);
1128 print_xlog_record_line();
1129 break;
1130 }
1131 }
1132
1133 /* Do we need to print the first part of physical log? */
1134 if (block_start != 0) {
1135 blkno = 0;
1136 xlog_print_lseek(log, fd, 0, SEEK_SET);
1137 for (;;) {
1138 if (read(fd, hbuf, 512) == 0) {
1139 xlog_panic("xlog_find_head: bad read");
1140 }
1141 if (print_only_data) {
1142 printf("BLKNO: %lld\n", (__int64_t)blkno);
1143 xlog_recover_print_data(hbuf, 512);
1144 blkno++;
1145 goto loop2;
1146 }
1147 num_ops = xlog_print_rec_head((xlog_rec_header_t *)hbuf, &len);
1148 blkno++;
1149
1150 if (num_ops == ZEROED_LOG || num_ops == BAD_HEADER) {
1151 /* we only expect zeroed log entries at the end
1152 * of the _physical_ log, so treat them the same
1153 * as bad blocks here
1154 */
1155 print_xlog_bad_header(blkno-1, hbuf);
1156
1157 if (blkno >= block_end)
1158 break;
1159 continue;
1160 }
1161 partial_log_read:
1162 error= xlog_print_record(fd, num_ops, len, &read_type,
1163 &partial_buf, (xlog_rec_header_t *)hbuf);
1164 if (read_type != FULL_READ)
1165 len -= read_type;
1166 read_type = FULL_READ;
1167 if (!error)
1168 blkno += BTOBB(len);
1169 else {
1170 print_xlog_bad_data(blkno-1);
1171 xlog_print_lseek(log, fd, blkno, SEEK_SET);
1172 goto loop2;
1173 }
1174 print_xlog_record_line();
1175 loop2:
1176 if (blkno >= block_end)
1177 break;
1178 }
1179 }
1180
1181 end:
1182 printf("%s: logical end of log\n", progname);
1183 print_xlog_record_line();
1184 }