Whamcloud - gitweb
Fix compile error and warnings for old gcc versions
[tools/e2fsprogs.git] / debugfs / logdump.c
1 /*
2  * logdump.c --- dump the contents of the journal out to a file
3  *
4  * Author: Stephen C. Tweedie, 2001  <sct@redhat.com>
5  * Copyright (C) 2001 Red Hat, Inc.
6  * Based on portions  Copyright (C) 1994 Theodore Ts'o.
7  *
8  * This file may be redistributed under the terms of the GNU Public
9  * License.
10  */
11
12 #include "config.h"
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17 #include <string.h>
18 #include <time.h>
19 #ifdef HAVE_ERRNO_H
20 #include <errno.h>
21 #endif
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <utime.h>
26 #ifdef HAVE_GETOPT_H
27 #include <getopt.h>
28 #else
29 extern int optind;
30 extern char *optarg;
31 #endif
32
33 #include "debugfs.h"
34 #include "blkid/blkid.h"
35 #include "jfs_user.h"
36 #include <uuid/uuid.h>
37
38 enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
39
40 #define ANY_BLOCK ((blk64_t) -1)
41
42 static int              dump_all, dump_super, dump_old, dump_contents, dump_descriptors;
43 static blk64_t          block_to_dump, bitmap_to_dump, inode_block_to_dump;
44 static unsigned int     group_to_dump, inode_offset_to_dump;
45 static ext2_ino_t       inode_to_dump;
46
47 struct journal_source
48 {
49         enum journal_location where;
50         int fd;
51         ext2_file_t file;
52 };
53
54 static void dump_journal(char *, FILE *, struct journal_source *);
55
56 static void dump_descriptor_block(FILE *, struct journal_source *,
57                                   char *, journal_superblock_t *,
58                                   unsigned int *, int, tid_t);
59
60 static void dump_revoke_block(FILE *, char *, journal_superblock_t *,
61                                   unsigned int, int, tid_t);
62
63 static void dump_metadata_block(FILE *, struct journal_source *,
64                                 journal_superblock_t*,
65                                 unsigned int, unsigned int, unsigned int,
66                                 int, tid_t);
67
68 static void do_hexdump (FILE *, char *, int);
69
70 #define WRAP(jsb, blocknr)                                      \
71         if (blocknr >= be32_to_cpu((jsb)->s_maxlen))            \
72                 blocknr -= (be32_to_cpu((jsb)->s_maxlen) -      \
73                             be32_to_cpu((jsb)->s_first));
74
75 void do_logdump(int argc, char **argv)
76 {
77         int             c;
78         int             retval;
79         char            *out_fn;
80         FILE            *out_file;
81
82         char            *inode_spec = NULL;
83         char            *journal_fn = NULL;
84         int             journal_fd = 0;
85         int             use_sb = 0;
86         ext2_ino_t      journal_inum;
87         struct ext2_inode journal_inode;
88         ext2_file_t     journal_file;
89         char            *tmp;
90         struct journal_source journal_source;
91         struct ext2_super_block *es = NULL;
92
93         journal_source.where = JOURNAL_IS_INTERNAL;
94         journal_source.fd = 0;
95         journal_source.file = 0;
96         dump_all = 0;
97         dump_old = 0;
98         dump_contents = 0;
99         dump_super = 0;
100         dump_descriptors = 1;
101         block_to_dump = ANY_BLOCK;
102         bitmap_to_dump = -1;
103         inode_block_to_dump = ANY_BLOCK;
104         inode_to_dump = -1;
105
106         reset_getopt();
107         while ((c = getopt (argc, argv, "ab:ci:f:OsS")) != EOF) {
108                 switch (c) {
109                 case 'a':
110                         dump_all++;
111                         break;
112                 case 'b':
113                         block_to_dump = strtoul(optarg, &tmp, 0);
114                         if (*tmp) {
115                                 com_err(argv[0], 0,
116                                         "Bad block number - %s", optarg);
117                                 return;
118                         }
119                         dump_descriptors = 0;
120                         break;
121                 case 'c':
122                         dump_contents++;
123                         break;
124                 case 'f':
125                         journal_fn = optarg;
126                         break;
127                 case 'i':
128                         inode_spec = optarg;
129                         dump_descriptors = 0;
130                         break;
131                 case 'O':
132                         dump_old++;
133                         break;
134                 case 's':
135                         use_sb++;
136                         break;
137                 case 'S':
138                         dump_super++;
139                         break;
140                 default:
141                         goto print_usage;
142                 }
143         }
144         if (optind != argc && optind != argc-1) {
145                 goto print_usage;
146         }
147
148         if (current_fs)
149                 es = current_fs->super;
150
151         if (inode_spec) {
152                 int inode_group, group_offset, inodes_per_block;
153
154                 if (check_fs_open(argv[0]))
155                         return;
156
157                 inode_to_dump = string_to_inode(inode_spec);
158                 if (!inode_to_dump)
159                         return;
160
161                 inode_group = ((inode_to_dump - 1)
162                                / es->s_inodes_per_group);
163                 group_offset = ((inode_to_dump - 1)
164                                 % es->s_inodes_per_group);
165                 inodes_per_block = (current_fs->blocksize
166                                     / sizeof(struct ext2_inode));
167
168                 inode_block_to_dump =
169                         ext2fs_inode_table_loc(current_fs, inode_group) +
170                         (group_offset / inodes_per_block);
171                 inode_offset_to_dump = ((group_offset % inodes_per_block)
172                                         * sizeof(struct ext2_inode));
173                 printf("Inode %u is at group %u, block %llu, offset %u\n",
174                        inode_to_dump, inode_group,
175                        inode_block_to_dump, inode_offset_to_dump);
176         }
177
178         if (optind == argc) {
179                 out_file = stdout;
180         } else {
181                 out_fn = argv[optind];
182                 out_file = fopen(out_fn, "w");
183                 if (!out_file) {
184                         com_err(argv[0], errno, "while opening %s for logdump",
185                                 out_fn);
186                         goto errout;
187                 }
188         }
189
190         if (block_to_dump != ANY_BLOCK && current_fs != NULL) {
191                 group_to_dump = ((block_to_dump -
192                                   es->s_first_data_block)
193                                  / es->s_blocks_per_group);
194                 bitmap_to_dump = ext2fs_block_bitmap_loc(current_fs, group_to_dump);
195         }
196
197         if (!journal_fn && check_fs_open(argv[0]))
198                 goto errout;
199
200         if (journal_fn) {
201                 /* Set up to read journal from a regular file somewhere */
202                 journal_fd = open(journal_fn, O_RDONLY, 0);
203                 if (journal_fd < 0) {
204                         com_err(argv[0], errno, "while opening %s for logdump",
205                                 journal_fn);
206                         goto errout;
207                 }
208
209                 journal_source.where = JOURNAL_IS_EXTERNAL;
210                 journal_source.fd = journal_fd;
211         } else if ((journal_inum = es->s_journal_inum)) {
212                 if (use_sb) {
213                         if (es->s_jnl_backup_type != EXT3_JNL_BACKUP_BLOCKS) {
214                                 com_err(argv[0], 0,
215                                         "no journal backup in super block\n");
216                                 goto errout;
217                         }
218                         memset(&journal_inode, 0, sizeof(struct ext2_inode));
219                         memcpy(&journal_inode.i_block[0], es->s_jnl_blocks,
220                                EXT2_N_BLOCKS*4);
221                         journal_inode.i_size_high = es->s_jnl_blocks[15];
222                         journal_inode.i_size = es->s_jnl_blocks[16];
223                         journal_inode.i_links_count = 1;
224                         journal_inode.i_mode = LINUX_S_IFREG | 0600;
225                 } else {
226                         if (debugfs_read_inode(journal_inum, &journal_inode,
227                                                argv[0]))
228                                 goto errout;
229                 }
230
231                 retval = ext2fs_file_open2(current_fs, journal_inum,
232                                            &journal_inode, 0, &journal_file);
233                 if (retval) {
234                         com_err(argv[0], retval, "while opening ext2 file");
235                         goto errout;
236                 }
237                 journal_source.where = JOURNAL_IS_INTERNAL;
238                 journal_source.file = journal_file;
239         } else {
240                 char uuid[37];
241
242                 uuid_unparse(es->s_journal_uuid, uuid);
243                 journal_fn = blkid_get_devname(NULL, "UUID", uuid);
244                 if (!journal_fn)
245                                 journal_fn = blkid_devno_to_devname(es->s_journal_dev);
246                 if (!journal_fn) {
247                         com_err(argv[0], 0, "filesystem has no journal");
248                         goto errout;
249                 }
250                 journal_fd = open(journal_fn, O_RDONLY, 0);
251                 if (journal_fd < 0) {
252                         com_err(argv[0], errno, "while opening %s for logdump",
253                                 journal_fn);
254                         free(journal_fn);
255                         goto errout;
256                 }
257                 fprintf(out_file, "Using external journal found at %s\n",
258                         journal_fn);
259                 free(journal_fn);
260                 journal_source.where = JOURNAL_IS_EXTERNAL;
261                 journal_source.fd = journal_fd;
262         }
263
264         dump_journal(argv[0], out_file, &journal_source);
265
266         if (journal_source.where == JOURNAL_IS_INTERNAL)
267                 ext2fs_file_close(journal_file);
268         else
269                 close(journal_fd);
270
271 errout:
272         if (out_file && (out_file != stdout))
273                 fclose(out_file);
274
275         return;
276
277 print_usage:
278         fprintf(stderr, "%s: Usage: logdump [-acsOS] [-b<block>] [-i<filespec>]\n\t"
279                 "[-f<journal_file>] [output_file]\n", argv[0]);
280 }
281
282
283 static int read_journal_block(const char *cmd, struct journal_source *source,
284                               ext2_loff_t offset, char *buf, unsigned int size)
285 {
286         int retval;
287         unsigned int got;
288
289         if (source->where == JOURNAL_IS_EXTERNAL) {
290                 if (lseek(source->fd, offset, SEEK_SET) < 0) {
291                         retval = errno;
292                         goto seek_err;
293                 }
294                 retval = read(source->fd, buf, size);
295                 if (retval < 0) {
296                         retval = errno;
297                         goto read_err;
298                 }
299                 got = retval;
300                 retval = 0;
301         } else {
302                 retval = ext2fs_file_llseek(source->file, offset,
303                                             EXT2_SEEK_SET, NULL);
304                 if (retval) {
305                 seek_err:
306                         com_err(cmd, retval, "while seeking in reading journal");
307                         return retval;
308                 }
309                 retval = ext2fs_file_read(source->file, buf, size, &got);
310                 if (retval) {
311                 read_err:
312                         com_err(cmd, retval, "while reading journal");
313                         return retval;
314                 }
315         }
316         if (got != size) {
317                 com_err(cmd, 0, "short read (read %u, expected %u) "
318                         "while reading journal", got, size);
319                 retval = -1;
320         }
321         return retval;
322 }
323
324 static const char *type_to_name(int btype)
325 {
326         switch (btype) {
327         case JFS_DESCRIPTOR_BLOCK:
328                 return "descriptor block";
329         case JFS_COMMIT_BLOCK:
330                 return "commit block";
331         case JFS_SUPERBLOCK_V1:
332                 return "V1 superblock";
333         case JFS_SUPERBLOCK_V2:
334                 return "V2 superblock";
335         case JFS_REVOKE_BLOCK:
336                 return "revoke table";
337         }
338         return "unrecognised type";
339 }
340
341
342 static void dump_journal(char *cmdname, FILE *out_file,
343                          struct journal_source *source)
344 {
345         struct ext2_super_block *sb;
346         char                    jsb_buffer[1024];
347         char                    buf[8192];
348         journal_superblock_t    *jsb;
349         unsigned int            blocksize = 1024;
350         int                     retval;
351         __u32                   magic, sequence, blocktype;
352         journal_header_t        *header;
353         tid_t                   transaction;
354         unsigned int            blocknr = 0;
355
356         /* First, check to see if there's an ext2 superblock header */
357         retval = read_journal_block(cmdname, source, 0, buf, 2048);
358         if (retval)
359                 return;
360
361         jsb = (journal_superblock_t *) buf;
362         sb = (struct ext2_super_block *) (buf+1024);
363 #ifdef WORDS_BIGENDIAN
364         if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
365                 ext2fs_swap_super(sb);
366 #endif
367
368         if ((be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) &&
369             (sb->s_magic == EXT2_SUPER_MAGIC) &&
370             ext2fs_has_feature_journal_dev(sb)) {
371                 blocksize = EXT2_BLOCK_SIZE(sb);
372                 blocknr = (blocksize == 1024) ? 2 : 1;
373                 uuid_unparse(sb->s_uuid, jsb_buffer);
374                 fprintf(out_file, "Ext2 superblock header found.\n");
375                 if (dump_all) {
376                         fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
377                         fprintf(out_file, "\tblocksize=%d\n", blocksize);
378                         fprintf(out_file, "\tjournal data size %lu\n",
379                                 (unsigned long) ext2fs_blocks_count(sb));
380                 }
381         }
382
383         /* Next, read the journal superblock */
384         retval = read_journal_block(cmdname, source,
385                                     ((ext2_loff_t) blocknr) * blocksize,
386                                     jsb_buffer, 1024);
387         if (retval)
388                 return;
389
390         if (dump_super) {
391                 e2p_list_journal_super(out_file, jsb_buffer,
392                                        current_fs->blocksize, 0);
393                 fputc('\n', out_file);
394         }
395
396         jsb = (journal_superblock_t *) jsb_buffer;
397         if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) {
398                 fprintf(out_file,
399                         "Journal superblock magic number invalid!\n");
400                 return;
401         }
402         blocksize = be32_to_cpu(jsb->s_blocksize);
403         transaction = be32_to_cpu(jsb->s_sequence);
404         blocknr = be32_to_cpu(jsb->s_start);
405
406         fprintf(out_file, "Journal starts at block %u, transaction %u\n",
407                 blocknr, transaction);
408
409         if (!blocknr) {
410                 /* Empty journal, nothing to do. */
411                 if (!dump_old)
412                         return;
413                 else
414                         blocknr = 1;
415         }
416
417         while (1) {
418                 retval = read_journal_block(cmdname, source,
419                                 ((ext2_loff_t) blocknr) * blocksize,
420                                 buf, blocksize);
421                 if (retval)
422                         return;
423
424                 header = (journal_header_t *) buf;
425
426                 magic = be32_to_cpu(header->h_magic);
427                 sequence = be32_to_cpu(header->h_sequence);
428                 blocktype = be32_to_cpu(header->h_blocktype);
429
430                 if (magic != JFS_MAGIC_NUMBER) {
431                         fprintf (out_file, "No magic number at block %u: "
432                                  "end of journal.\n", blocknr);
433                         return;
434                 }
435
436                 if (sequence != transaction) {
437                         fprintf (out_file, "Found sequence %u (not %u) at "
438                                  "block %u: end of journal.\n",
439                                  sequence, transaction, blocknr);
440                         if (!dump_old)
441                                 return;
442                 }
443
444                 if (dump_descriptors) {
445                         fprintf (out_file, "Found expected sequence %u, "
446                                  "type %u (%s) at block %u\n",
447                                  sequence, blocktype,
448                                  type_to_name(blocktype), blocknr);
449                 }
450
451                 switch (blocktype) {
452                 case JFS_DESCRIPTOR_BLOCK:
453                         dump_descriptor_block(out_file, source, buf, jsb,
454                                               &blocknr, blocksize,
455                                               transaction);
456                         continue;
457
458                 case JFS_COMMIT_BLOCK:
459                         transaction++;
460                         blocknr++;
461                         WRAP(jsb, blocknr);
462                         continue;
463
464                 case JFS_REVOKE_BLOCK:
465                         dump_revoke_block(out_file, buf, jsb,
466                                           blocknr, blocksize,
467                                           transaction);
468                         blocknr++;
469                         WRAP(jsb, blocknr);
470                         continue;
471
472                 default:
473                         fprintf (out_file, "Unexpected block type %u at "
474                                  "block %u.\n", blocktype, blocknr);
475                         return;
476                 }
477         }
478 }
479
480 static inline size_t journal_super_tag_bytes(journal_superblock_t *jsb)
481 {
482         size_t sz;
483
484         if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V3))
485                 return sizeof(journal_block_tag3_t);
486
487         sz = sizeof(journal_block_tag_t);
488
489         if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V2))
490                 sz += sizeof(__u16);
491
492         if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_64BIT))
493                 return sz;
494
495         return sz - sizeof(__u32);
496 }
497
498 static void dump_descriptor_block(FILE *out_file,
499                                   struct journal_source *source,
500                                   char *buf,
501                                   journal_superblock_t *jsb,
502                                   unsigned int *blockp, int blocksize,
503                                   tid_t transaction)
504 {
505         int                     offset, tag_size, csum_size = 0;
506         char                    *tagp;
507         journal_block_tag_t     *tag;
508         unsigned int            blocknr;
509         __u32                   tag_block;
510         __u32                   tag_flags;
511
512         tag_size = journal_super_tag_bytes(jsb);
513         offset = sizeof(journal_header_t);
514         blocknr = *blockp;
515
516         if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V3) ||
517             JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V2))
518                 csum_size = sizeof(struct journal_block_tail);
519
520         if (dump_all)
521                 fprintf(out_file, "Dumping descriptor block, sequence %u, at "
522                         "block %u:\n", transaction, blocknr);
523
524         ++blocknr;
525         WRAP(jsb, blocknr);
526
527         do {
528                 /* Work out the location of the current tag, and skip to
529                  * the next one... */
530                 tagp = &buf[offset];
531                 tag = (journal_block_tag_t *) tagp;
532                 offset += tag_size;
533
534                 /* ... and if we have gone too far, then we've reached the
535                    end of this block. */
536                 if (offset > blocksize - csum_size)
537                         break;
538
539                 tag_block = be32_to_cpu(tag->t_blocknr);
540                 tag_flags = be16_to_cpu(tag->t_flags);
541
542                 if (!(tag_flags & JFS_FLAG_SAME_UUID))
543                         offset += 16;
544
545                 dump_metadata_block(out_file, source, jsb,
546                                     blocknr, tag_block, tag_flags, blocksize,
547                                     transaction);
548
549                 ++blocknr;
550                 WRAP(jsb, blocknr);
551
552         } while (!(tag_flags & JFS_FLAG_LAST_TAG));
553
554         *blockp = blocknr;
555 }
556
557
558 static void dump_revoke_block(FILE *out_file, char *buf,
559                               journal_superblock_t *jsb EXT2FS_ATTR((unused)),
560                               unsigned int blocknr,
561                               int blocksize EXT2FS_ATTR((unused)),
562                               tid_t transaction)
563 {
564         int                     offset, max;
565         journal_revoke_header_t *header;
566         unsigned long long      rblock;
567         int                     tag_size = sizeof(__u32);
568
569         if (dump_all)
570                 fprintf(out_file, "Dumping revoke block, sequence %u, at "
571                         "block %u:\n", transaction, blocknr);
572
573         if (be32_to_cpu(jsb->s_feature_incompat) & JFS_FEATURE_INCOMPAT_64BIT)
574                 tag_size = sizeof(__u64);
575
576         header = (journal_revoke_header_t *) buf;
577         offset = sizeof(journal_revoke_header_t);
578         max = be32_to_cpu(header->r_count);
579
580         while (offset < max) {
581                 if (tag_size == sizeof(__u32)) {
582                         __u32 *entry = (__u32 *) (buf + offset);
583                         rblock = be32_to_cpu(*entry);
584                 } else {
585                         __u64 *entry = (__u64 *) (buf + offset);
586                         rblock = ext2fs_be64_to_cpu(*entry);
587                 }
588                 if (dump_all || rblock == block_to_dump) {
589                         fprintf(out_file, "  Revoke FS block %llu", rblock);
590                         if (dump_all)
591                                 fprintf(out_file, "\n");
592                         else
593                                 fprintf(out_file," at block %u, sequence %u\n",
594                                         blocknr, transaction);
595                 }
596                 offset += tag_size;
597         }
598 }
599
600
601 static void show_extent(FILE *out_file, int start_extent, int end_extent,
602                         __u32 first_block)
603 {
604         if (start_extent >= 0 && first_block != 0)
605                 fprintf(out_file, "(%d+%u): %u ",
606                         start_extent, end_extent-start_extent, first_block);
607 }
608
609 static void show_indirect(FILE *out_file, const char *name, __u32 where)
610 {
611         if (where)
612                 fprintf(out_file, "(%s): %u ", name, where);
613 }
614
615
616 static void dump_metadata_block(FILE *out_file, struct journal_source *source,
617                                 journal_superblock_t *jsb EXT2FS_ATTR((unused)),
618                                 unsigned int log_blocknr,
619                                 unsigned int fs_blocknr,
620                                 unsigned int log_tag_flags,
621                                 int blocksize,
622                                 tid_t transaction)
623 {
624         int             retval;
625         char            buf[8192];
626
627         if (!(dump_all
628               || (fs_blocknr == block_to_dump)
629               || (fs_blocknr == inode_block_to_dump)
630               || (fs_blocknr == bitmap_to_dump)))
631                 return;
632
633         fprintf(out_file, "  FS block %u logged at ", fs_blocknr);
634         if (!dump_all)
635                 fprintf(out_file, "sequence %u, ", transaction);
636         fprintf(out_file, "journal block %u (flags 0x%x)\n", log_blocknr,
637                 log_tag_flags);
638
639         /* There are two major special cases to parse:
640          *
641          * If this block is a block
642          * bitmap block, we need to give it special treatment so that we
643          * can log any allocates and deallocates which affect the
644          * block_to_dump query block.
645          *
646          * If the block is an inode block for the inode being searched
647          * for, then we need to dump the contents of that inode
648          * structure symbolically.
649          */
650
651         if (!(dump_contents && dump_all)
652             && fs_blocknr != block_to_dump
653             && fs_blocknr != bitmap_to_dump
654             && fs_blocknr != inode_block_to_dump)
655                 return;
656
657         retval = read_journal_block("logdump", source,
658                                     ((ext2_loff_t) log_blocknr) * blocksize,
659                                     buf, blocksize);
660         if (retval)
661                 return;
662
663         if (fs_blocknr == bitmap_to_dump) {
664                 struct ext2_super_block *super;
665                 int offset;
666
667                 super = current_fs->super;
668                 offset = ((block_to_dump - super->s_first_data_block) %
669                           super->s_blocks_per_group);
670
671                 fprintf(out_file, "    (block bitmap for block %llu: "
672                         "block is %s)\n",
673                         block_to_dump,
674                         ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");
675         }
676
677         if (fs_blocknr == inode_block_to_dump) {
678                 struct ext2_inode *inode;
679                 int first, prev, this, start_extent, i;
680
681                 fprintf(out_file, "    (inode block for inode %u):\n",
682                         inode_to_dump);
683
684                 inode = (struct ext2_inode *) (buf + inode_offset_to_dump);
685                 internal_dump_inode(out_file, "    ", inode_to_dump, inode, 0);
686
687                 /* Dump out the direct/indirect blocks here:
688                  * internal_dump_inode can only dump them from the main
689                  * on-disk inode, not from the journaled copy of the
690                  * inode. */
691
692                 fprintf (out_file, "    Blocks:  ");
693                 first = prev = start_extent = -1;
694
695                 for (i=0; i<EXT2_NDIR_BLOCKS; i++) {
696                         this = inode->i_block[i];
697                         if (start_extent >= 0  && this == prev+1) {
698                                 prev = this;
699                                 continue;
700                         } else {
701                                 show_extent(out_file, start_extent, i, first);
702                                 start_extent = i;
703                                 first = prev = this;
704                         }
705                 }
706                 show_extent(out_file, start_extent, i, first);
707                 show_indirect(out_file, "IND", inode->i_block[i++]);
708                 show_indirect(out_file, "DIND", inode->i_block[i++]);
709                 show_indirect(out_file, "TIND", inode->i_block[i++]);
710
711                 fprintf(out_file, "\n");
712         }
713
714         if (dump_contents)
715                 do_hexdump(out_file, buf, blocksize);
716
717 }
718
719 static void do_hexdump (FILE *out_file, char *buf, int blocksize)
720 {
721         int i,j;
722         int *intp;
723         char *charp;
724         unsigned char c;
725
726         intp = (int *) buf;
727         charp = (char *) buf;
728
729         for (i=0; i<blocksize; i+=16) {
730                 fprintf(out_file, "    %04x:  ", i);
731                 for (j=0; j<16; j+=4)
732                         fprintf(out_file, "%08x ", *intp++);
733                 for (j=0; j<16; j++) {
734                         c = *charp++;
735                         if (c < ' ' || c >= 127)
736                                 c = '.';
737                         fprintf(out_file, "%c", c);
738                 }
739                 fprintf(out_file, "\n");
740         }
741 }
742