2 * Copyright (c) 2007, 2011 SGI
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
29 #include "xfs_metadump.h"
35 #define DEFAULT_MAX_EXT_SIZE 1000
38 * It's possible that multiple files in a directory (or attributes
39 * in a file) produce the same obfuscated name. If that happens, we
40 * try to create another one. After several rounds of this though,
41 * we just give up and leave the original name as-is.
43 #define DUP_MAX 5 /* Max duplicates before we give up */
45 /* copy all metadata structures to/from a file */
47 static int metadump_f(int argc
, char **argv
);
48 static void metadump_help(void);
51 * metadump commands issue info/wornings/errors to standard error as
52 * metadump supports stdout as a destination.
54 * All static functions return zero on failure, while the public functions
55 * return zero on success.
58 static const cmdinfo_t metadump_cmd
=
59 { "metadump", NULL
, metadump_f
, 0, -1, 0,
60 N_("[-a] [-e] [-g] [-m max_extent] [-w] [-o] filename"),
61 N_("dump metadata to a file"), metadump_help
};
63 static FILE *outf
; /* metadump file */
65 static xfs_metablock_t
*metablock
; /* header + index + buffers */
66 static __be64
*block_index
;
67 static char *block_buffer
;
69 static int num_indicies
;
72 static xfs_ino_t cur_ino
;
74 static int show_progress
= 0;
75 static int stop_on_read_error
= 0;
76 static int max_extent_size
= DEFAULT_MAX_EXT_SIZE
;
77 static int obfuscate
= 1;
78 static int zero_stale_data
= 1;
79 static int show_warnings
= 0;
80 static int progress_since_warning
= 0;
85 add_command(&metadump_cmd
);
93 " The 'metadump' command dumps the known metadata to a compact file suitable\n"
94 " for compressing and sending to an XFS maintainer for corruption analysis \n"
95 " or xfs_repair failures.\n\n"
97 " -a -- Copy full metadata blocks without zeroing unused space\n"
98 " -e -- Ignore read errors and keep going\n"
99 " -g -- Display dump progress\n"
100 " -m -- Specify max extent size in blocks to copy (default = %d blocks)\n"
101 " -o -- Don't obfuscate names and extended attributes\n"
102 " -w -- Show warnings of bad metadata information\n"
103 "\n"), DEFAULT_MAX_EXT_SIZE
);
107 print_warning(const char *fmt
, ...)
116 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
118 buf
[sizeof(buf
)-1] = '\0';
120 fprintf(stderr
, "%s%s: %s\n", progress_since_warning
? "\n" : "",
122 progress_since_warning
= 0;
126 print_progress(const char *fmt
, ...)
136 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
138 buf
[sizeof(buf
)-1] = '\0';
140 f
= (outf
== stdout
) ? stderr
: stdout
;
141 fprintf(f
, "\r%-59s", buf
);
143 progress_since_warning
= 1;
147 * A complete dump file will have a "zero" entry in the last index block,
148 * even if the dump is exactly aligned, the last index will be full of
149 * zeros. If the last index entry is non-zero, the dump is incomplete.
150 * Correspondingly, the last chunk will have a count < num_indicies.
152 * Return 0 for success, -1 for failure.
159 * write index block and following data blocks (streaming)
161 metablock
->mb_count
= cpu_to_be16(cur_index
);
162 if (fwrite(metablock
, (cur_index
+ 1) << BBSHIFT
, 1, outf
) != 1) {
163 print_warning("error writing to file: %s", strerror(errno
));
167 memset(block_index
, 0, num_indicies
* sizeof(__be64
));
173 * Return 0 for success, -errno for failure.
184 for (i
= 0; i
< len
; i
++, off
++, data
+= BBSIZE
) {
185 block_index
[cur_index
] = cpu_to_be64(off
);
186 memcpy(&block_buffer
[cur_index
<< BBSHIFT
], data
, BBSIZE
);
187 if (++cur_index
== num_indicies
) {
197 * we want to preserve the state of the metadata in the dump - whether it is
198 * intact or corrupt, so even if the buffer has a verifier attached to it we
199 * don't want to run it prior to writing the buffer to the metadump image.
201 * The only reason for running the verifier is to recalculate the CRCs on a
202 * buffer that has been obfuscated. i.e. a buffer than metadump modified itself.
203 * In this case, we only run the verifier if the buffer was not corrupt to begin
204 * with so that we don't accidentally correct buffers with CRC or errors in them
205 * when we are obfuscating them.
211 struct xfs_buf
*bp
= buf
->bp
;
216 * Run the write verifier to recalculate the buffer CRCs and check
217 * metadump didn't introduce a new corruption. Warn if the verifier
218 * failed, but still continue to dump it into the output file.
220 if (buf
->need_crc
&& bp
&& bp
->b_ops
&& !bp
->b_error
) {
221 bp
->b_ops
->verify_write(bp
);
224 "obfuscation corrupted block at bno 0x%llx/0x%x",
225 (long long)bp
->b_bn
, bp
->b_bcount
);
229 /* handle discontiguous buffers */
231 ret
= write_buf_segment(buf
->data
, buf
->bb
, buf
->blen
);
236 for (i
= 0; i
< buf
->bbmap
->nmaps
; i
++) {
237 ret
= write_buf_segment(buf
->data
+ BBTOB(len
),
238 buf
->bbmap
->b
[i
].bm_bn
,
239 buf
->bbmap
->b
[i
].bm_len
);
242 len
+= buf
->bbmap
->b
[i
].bm_len
;
245 return seenint() ? -EINTR
: 0;
250 struct xfs_btree_block
*block
,
256 xfs_inobt_ptr_t
*ipp
;
257 xfs_inobt_key_t
*ikp
;
258 xfs_alloc_ptr_t
*app
;
259 xfs_alloc_key_t
*akp
;
263 nrecs
= be16_to_cpu(block
->bb_numrecs
);
268 bkp
= XFS_BMBT_KEY_ADDR(mp
, block
, 1);
269 bpp
= XFS_BMBT_PTR_ADDR(mp
, block
, 1, mp
->m_bmap_dmxr
[1]);
271 zlen1
= (char *)&bpp
[0] - (char *)&bkp
[nrecs
];
273 zlen2
= (char *)block
+ mp
->m_sb
.sb_blocksize
-
278 ikp
= XFS_INOBT_KEY_ADDR(mp
, block
, 1);
279 ipp
= XFS_INOBT_PTR_ADDR(mp
, block
, 1, mp
->m_inobt_mxr
[1]);
281 zlen1
= (char *)&ipp
[0] - (char *)&ikp
[nrecs
];
283 zlen2
= (char *)block
+ mp
->m_sb
.sb_blocksize
-
288 akp
= XFS_ALLOC_KEY_ADDR(mp
, block
, 1);
289 app
= XFS_ALLOC_PTR_ADDR(mp
, block
, 1, mp
->m_alloc_mxr
[1]);
291 zlen1
= (char *)&app
[0] - (char *)&akp
[nrecs
];
293 zlen2
= (char *)block
+ mp
->m_sb
.sb_blocksize
-
302 /* Zero from end of keys to beginning of pointers */
303 memset(zp1
, 0, zlen1
);
304 /* Zero from end of pointers to end of block */
305 memset(zp2
, 0, zlen2
);
311 struct xfs_btree_block
*block
,
315 struct xfs_bmbt_rec
*brp
;
316 struct xfs_inobt_rec
*irp
;
317 struct xfs_alloc_rec
*arp
;
321 nrecs
= be16_to_cpu(block
->bb_numrecs
);
326 brp
= XFS_BMBT_REC_ADDR(mp
, block
, 1);
328 zlen
= (char *)block
+ mp
->m_sb
.sb_blocksize
- (char *)&brp
[nrecs
];
332 irp
= XFS_INOBT_REC_ADDR(mp
, block
, 1);
334 zlen
= (char *)block
+ mp
->m_sb
.sb_blocksize
- (char *)&irp
[nrecs
];
338 arp
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
340 zlen
= (char *)block
+ mp
->m_sb
.sb_blocksize
- (char *)&arp
[nrecs
];
347 /* Zero from end of records to end of block */
348 if (zp
&& zlen
< mp
->m_sb
.sb_blocksize
)
354 struct xfs_btree_block
*block
,
359 level
= be16_to_cpu(block
->bb_level
);
362 zero_btree_node(block
, btype
);
364 zero_btree_leaf(block
, btype
);
374 int (*func
)(struct xfs_btree_block
*block
,
384 set_cur(&typtab
[btype
], XFS_AGB_TO_DADDR(mp
, agno
, agbno
), blkbb
,
386 if (iocur_top
->data
== NULL
) {
387 print_warning("cannot read %s block %u/%u", typtab
[btype
].name
,
389 rval
= !stop_on_read_error
;
393 if (zero_stale_data
) {
394 zero_btree_block(iocur_top
->data
, btype
);
395 iocur_top
->need_crc
= 1;
398 if (write_buf(iocur_top
))
401 if (!(*func
)(iocur_top
->data
, agno
, agbno
, level
- 1, btype
, arg
))
409 /* free space tree copy routines */
416 if (agno
< (mp
->m_sb
.sb_agcount
- 1) && agbno
> 0 &&
417 agbno
<= mp
->m_sb
.sb_agblocks
)
419 if (agno
== (mp
->m_sb
.sb_agcount
- 1) && agbno
> 0 &&
420 agbno
<= (mp
->m_sb
.sb_dblocks
-
421 (xfs_rfsblock_t
)(mp
->m_sb
.sb_agcount
- 1) *
422 mp
->m_sb
.sb_agblocks
))
431 struct xfs_btree_block
*block
,
445 numrecs
= be16_to_cpu(block
->bb_numrecs
);
446 if (numrecs
> mp
->m_alloc_mxr
[1]) {
448 print_warning("invalid numrecs (%u) in %s block %u/%u",
449 numrecs
, typtab
[btype
].name
, agno
, agbno
);
453 pp
= XFS_ALLOC_PTR_ADDR(mp
, block
, 1, mp
->m_alloc_mxr
[1]);
454 for (i
= 0; i
< numrecs
; i
++) {
455 if (!valid_bno(agno
, be32_to_cpu(pp
[i
]))) {
457 print_warning("invalid block number (%u/%u) "
459 agno
, be32_to_cpu(pp
[i
]),
460 typtab
[btype
].name
, agno
, agbno
);
463 if (!scan_btree(agno
, be32_to_cpu(pp
[i
]), level
, btype
, arg
,
478 root
= be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_BNO
]);
479 levels
= be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_BNO
]);
481 /* validate root and levels before processing the tree */
482 if (root
== 0 || root
> mp
->m_sb
.sb_agblocks
) {
484 print_warning("invalid block number (%u) in bnobt "
485 "root in agf %u", root
, agno
);
488 if (levels
>= XFS_BTREE_MAXLEVELS
) {
490 print_warning("invalid level (%u) in bnobt root "
491 "in agf %u", levels
, agno
);
495 return scan_btree(agno
, root
, levels
, TYP_BNOBT
, agf
, scanfunc_freesp
);
506 root
= be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_CNT
]);
507 levels
= be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_CNT
]);
509 /* validate root and levels before processing the tree */
510 if (root
== 0 || root
> mp
->m_sb
.sb_agblocks
) {
512 print_warning("invalid block number (%u) in cntbt "
513 "root in agf %u", root
, agno
);
516 if (levels
>= XFS_BTREE_MAXLEVELS
) {
518 print_warning("invalid level (%u) in cntbt root "
519 "in agf %u", levels
, agno
);
523 return scan_btree(agno
, root
, levels
, TYP_CNTBT
, agf
, scanfunc_freesp
);
526 /* filename and extended attribute obfuscation routines */
529 struct name_ent
*next
;
535 #define NAME_TABLE_SIZE 4096
537 static struct name_ent
*nametable
[NAME_TABLE_SIZE
];
540 nametable_clear(void)
543 struct name_ent
*ent
;
545 for (i
= 0; i
< NAME_TABLE_SIZE
; i
++) {
546 while ((ent
= nametable
[i
])) {
547 nametable
[i
] = ent
->next
;
554 * See if the given name is already in the name table. If so,
555 * return a pointer to its entry, otherwise return a null pointer.
557 static struct name_ent
*
558 nametable_find(xfs_dahash_t hash
, int namelen
, uchar_t
*name
)
560 struct name_ent
*ent
;
562 for (ent
= nametable
[hash
% NAME_TABLE_SIZE
]; ent
; ent
= ent
->next
) {
563 if (ent
->hash
== hash
&& ent
->namelen
== namelen
&&
564 !memcmp(ent
->name
, name
, namelen
))
571 * Add the given name to the name table. Returns a pointer to the
572 * name's new entry, or a null pointer if an error occurs.
574 static struct name_ent
*
575 nametable_add(xfs_dahash_t hash
, int namelen
, uchar_t
*name
)
577 struct name_ent
*ent
;
579 ent
= malloc(sizeof *ent
+ namelen
);
583 ent
->namelen
= namelen
;
584 memcpy(ent
->name
, name
, namelen
);
586 ent
->next
= nametable
[hash
% NAME_TABLE_SIZE
];
588 nametable
[hash
% NAME_TABLE_SIZE
] = ent
;
593 #define is_invalid_char(c) ((c) == '/' || (c) == '\0')
594 #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
596 static inline uchar_t
597 random_filename_char(void)
599 static uchar_t filename_alphabet
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
600 "abcdefghijklmnopqrstuvwxyz"
603 return filename_alphabet
[random() % (sizeof filename_alphabet
- 1)];
606 #define ORPHANAGE "lost+found"
607 #define ORPHANAGE_LEN (sizeof (ORPHANAGE) - 1)
611 struct xfs_mount
*mp
,
616 return dir_ino
== mp
->m_sb
.sb_rootino
&&
617 name_len
== ORPHANAGE_LEN
&&
618 !memcmp(name
, ORPHANAGE
, ORPHANAGE_LEN
);
622 * Determine whether a name is one we shouldn't obfuscate because
623 * it's an orphan (or the "lost+found" directory itself). Note
624 * "cur_ino" is the inode for the directory currently being
627 * Returns 1 if the name should NOT be obfuscated or 0 otherwise.
635 static xfs_ino_t orphanage_ino
= 0;
636 char s
[24]; /* 21 is enough (64 bits in decimal) */
639 /* Record the "lost+found" inode if we haven't done so already */
642 if (!orphanage_ino
&& is_orphanage_dir(mp
, cur_ino
, namelen
, name
))
645 /* We don't obfuscate the "lost+found" directory itself */
647 if (ino
== orphanage_ino
)
650 /* Most files aren't in "lost+found" at all */
652 if (cur_ino
!= orphanage_ino
)
656 * Within "lost+found", we don't obfuscate any file whose
657 * name is the same as its inode number. Any others are
658 * stray files and can be obfuscated.
660 slen
= snprintf(s
, sizeof (s
), "%llu", (unsigned long long) ino
);
662 return slen
== namelen
&& !memcmp(name
, s
, namelen
);
666 * Given a name and its hash value, massage the name in such a way
667 * that the result is another name of equal length which shares the
676 uchar_t
*newp
= name
;
678 xfs_dahash_t new_hash
= 0;
684 * Our obfuscation algorithm requires at least 5-character
685 * names, so don't bother if the name is too short. We
686 * work backward from a hash value to determine the last
687 * five bytes in a name required to produce a new name
688 * with the same hash.
694 * The beginning of the obfuscated name can be pretty much
695 * anything, so fill it in with random characters.
696 * Accumulate its new hash value as we go.
698 for (i
= 0; i
< name_len
- 5; i
++) {
699 *newp
= random_filename_char();
700 new_hash
= *newp
^ rol32(new_hash
, 7);
705 * Compute which five bytes need to be used at the end of
706 * the name so the hash of the obfuscated name is the same
707 * as the hash of the original. If any result in an invalid
708 * character, flip a bit and arrange for a corresponding bit
709 * in a neighboring byte to be flipped as well. For the
710 * last byte, the "neighbor" to change is the first byte
711 * we're computing here.
713 new_hash
= rol32(new_hash
, 3) ^ hash
;
717 for (shift
= 28; shift
>= 0; shift
-= 7) {
718 *newp
= (new_hash
>> shift
& 0x7f) ^ high_bit
;
719 if (is_invalid_char(*newp
)) {
724 ASSERT(!is_invalid_char(*newp
));
729 * If we flipped a bit on the last byte, we need to fix up
730 * the matching bit in the first byte. The result will
731 * be a valid character, because we know that first byte
732 * has 0's in its upper four bits (it was produced by a
733 * 28-bit right-shift of a 32-bit unsigned value).
737 ASSERT(!is_invalid_char(*first
));
739 ASSERT(libxfs_da_hashname(name
, name_len
) == hash
);
743 * Flip a bit in each of two bytes at the end of the given name.
744 * This is used in generating a series of alternate names to be used
745 * in the event a duplicate is found.
747 * The bits flipped are selected such that they both affect the same
748 * bit in the name's computed hash value, so flipping them both will
751 * The following diagram aims to show the portion of a computed
752 * hash that a given byte of a name affects.
754 * 31 28 24 21 14 8 7 3 0
755 * +-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-+
756 * hash: | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
757 * +-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-+
758 * last-4 ->| |<-- last-2 --->| |<--- last ---->|
759 * |<-- last-3 --->| |<-- last-1 --->| |<- last-4
760 * |<-- last-7 --->| |<-- last-5 --->|
761 * |<-- last-8 --->| |<-- last-6 --->|
764 * The last byte of the name directly affects the low-order byte of
765 * the hash. The next-to-last affects bits 7-14, the next one back
766 * affects bits 14-21, and so on. The effect wraps around when it
767 * goes beyond the top of the hash (as happens for byte last-4).
769 * Bits that are flipped together "overlap" on the hash value. As
770 * an example of overlap, the last two bytes both affect bit 7 in
771 * the hash. That pair of bytes (and their overlapping bits) can be
772 * used for this "flip bit" operation (it's the first pair tried,
775 * A table defines overlapping pairs--the bytes involved and bits
776 * within them--that can be used this way. The byte offset is
777 * relative to a starting point within the name, which will be set
778 * to affect the bytes at the end of the name. The function is
779 * called with a "bitseq" value which indicates which bit flip is
780 * desired, and this translates directly into selecting which entry
781 * in the bit_to_flip[] table to apply.
783 * The function returns 1 if the operation was successful. It
784 * returns 0 if the result produced a character that's not valid in
785 * a name (either '/' or a '\0'). Finally, it returns -1 if the bit
786 * sequence number is beyond what is supported for a name of this
791 * (Also see the discussion above find_alternate(), below.)
793 * In order to make this function work for any length name, the
794 * table is ordered by increasing byte offset, so that the earliest
795 * entries can apply to the shortest strings. This way all names
796 * are done consistently.
798 * When bit flips occur, they can convert printable characters
799 * into non-printable ones. In an effort to reduce the impact of
800 * this, the first bit flips are chosen to affect bytes the end of
801 * the name (and furthermore, toward the low bits of a byte). Those
802 * bytes are often non-printable anyway because of the way they are
803 * initially selected by obfuscate_name()). This is accomplished,
804 * using later table entries first.
806 * Each row in the table doubles the number of alternates that
807 * can be generated. A two-byte name is limited to using only
808 * the first row, so it's possible to generate two alternates
809 * (the original name, plus the alternate produced by flipping
810 * the one pair of bits). In a 5-byte name, the effect of the
811 * first byte overlaps the last by 4 its, and there are 8 bits
812 * to flip, allowing for 256 possible alternates.
814 * Short names (less than 5 bytes) are never even obfuscated, so for
815 * such names the relatively small number of alternates should never
816 * really be a problem.
818 * Long names (more than 6 bytes, say) are not likely to exhaust
819 * the number of available alternates. In fact, the table could
820 * probably have stopped at 8 entries, on the assumption that 256
821 * alternates should be enough for most any situation. The entries
822 * beyond those are present mostly for demonstration of how it could
823 * be populated with more entries, should it ever be necessary to do
837 int byte
; /* Offset from start within name */
838 uchar_t bit
; /* Bit within that byte */
839 } bit_to_flip
[][2] = { /* Sorted by second entry's byte */
840 { { 0, 0 }, { 1, 7 } }, /* Each row defines a pair */
841 { { 1, 0 }, { 2, 7 } }, /* of bytes and a bit within */
842 { { 2, 0 }, { 3, 7 } }, /* each byte. Each bit in */
843 { { 0, 4 }, { 4, 0 } }, /* a pair affects the same */
844 { { 0, 5 }, { 4, 1 } }, /* bit in the hash, so flipping */
845 { { 0, 6 }, { 4, 2 } }, /* both will change the name */
846 { { 0, 7 }, { 4, 3 } }, /* while preserving the hash. */
847 { { 3, 0 }, { 4, 7 } },
848 { { 0, 0 }, { 5, 3 } }, /* The first entry's byte offset */
849 { { 0, 1 }, { 5, 4 } }, /* must be less than the second. */
850 { { 0, 2 }, { 5, 5 } },
851 { { 0, 3 }, { 5, 6 } }, /* The table can be extended to */
852 { { 0, 4 }, { 5, 7 } }, /* an arbitrary number of entries */
853 { { 4, 0 }, { 5, 7 } }, /* but there's not much point. */
857 /* Find the first entry *not* usable for name of this length */
859 for (index
= 0; index
< ARRAY_SIZE(bit_to_flip
); index
++)
860 if (bit_to_flip
[index
][1].byte
>= name_len
)
864 * Back up to the last usable entry. If that number is
865 * smaller than the bit sequence number, inform the caller
866 * that nothing this large (or larger) will work.
868 if (bitseq
> --index
)
872 * We will be switching bits at the end of name, with a
873 * preference for affecting the last bytes first. Compute
874 * where in the name we'll start applying the changes.
876 offset
= name_len
- (bit_to_flip
[index
][1].byte
+ 1);
877 index
-= bitseq
; /* Use later table entries first */
879 p0
= name
+ offset
+ bit_to_flip
[index
][0].byte
;
880 p1
= name
+ offset
+ bit_to_flip
[index
][1].byte
;
881 m0
= 1 << bit_to_flip
[index
][0].bit
;
882 m1
= 1 << bit_to_flip
[index
][1].bit
;
884 /* Only change the bytes if it produces valid characters */
886 if (is_invalid_char(*p0
^ m0
) || is_invalid_char(*p1
^ m1
))
896 * This function generates a well-defined sequence of "alternate"
897 * names for a given name. An alternate is a name having the same
898 * length and same hash value as the original name. This is needed
899 * because the algorithm produces only one obfuscated name to use
900 * for a given original name, and it's possible that result matches
901 * a name already seen. This function checks for this, and if it
902 * occurs, finds another suitable obfuscated name to use.
904 * Each bit in the binary representation of the sequence number is
905 * used to select one possible "bit flip" operation to perform on
906 * the name. So for example:
907 * seq = 0: selects no bits to flip
908 * seq = 1: selects the 0th bit to flip
909 * seq = 2: selects the 1st bit to flip
910 * seq = 3: selects the 0th and 1st bit to flip
913 * The flip_bit() function takes care of the details of the bit
914 * flipping within the name. Note that the "1st bit" in this
915 * context is a bit sequence number; i.e. it doesn't necessarily
916 * mean bit 0x02 will be changed.
918 * If a valid name (one that contains no '/' or '\0' characters) is
919 * produced by this process for the given sequence number, this
920 * function returns 1. If the result is not valid, it returns 0.
921 * Returns -1 if the sequence number is beyond the the maximum for
922 * names of the given length.
927 * The number of alternates available for a given name is dependent
928 * on its length. A "bit flip" involves inverting two bits in
929 * a name--the two bits being selected such that their values
930 * affect the name's hash value in the same way. Alternates are
931 * thus generated by inverting the value of pairs of such
932 * "overlapping" bits in the original name. Each byte after the
933 * first in a name adds at least one bit of overlap to work with.
934 * (See comments above flip_bit() for more discussion on this.)
936 * So the number of alternates is dependent on the number of such
937 * overlapping bits in a name. If there are N bit overlaps, there
938 * 2^N alternates for that hash value.
940 * Here are the number of overlapping bits available for generating
941 * alternates for names of specific lengths:
942 * 1 0 (must have 2 bytes to have any overlap)
943 * 2 1 One bit overlaps--so 2 possible alternates
944 * 3 2 Two bits overlap--so 4 possible alternates
945 * 4 4 Three bits overlap, so 2^3 alternates
946 * 5 8 8 bits overlap (due to wrapping), 256 alternates
947 * 6 18 2^18 alternates
948 * 7 28 2^28 alternates
950 * It's clear that the number of alternates grows very quickly with
951 * the length of the name. But note that the set of alternates
952 * includes invalid names. And for certain (contrived) names, the
953 * number of valid names is a fairly small fraction of the total
954 * number of alternates.
956 * The main driver for this infrastructure for coming up with
957 * alternate names is really related to names 5 (or possibly 6)
958 * bytes in length. 5-byte obfuscated names contain no randomly-
959 * generated bytes in them, and the chance of an obfuscated name
960 * matching an already-seen name is too high to just ignore. This
961 * methodical selection of alternates ensures we don't produce
962 * duplicate names unless we have exhausted our options.
974 return 1; /* alternate 0 is the original name */
975 if (name_len
< 2) /* Must have 2 bytes to flip */
978 for (bitseq
= 0; bits
; bitseq
++) {
979 uint32_t mask
= 1 << bitseq
;
985 fb
= flip_bit(name_len
, name
, bitseq
);
995 * Look up the given name in the name table. If it is already
996 * present, iterate through a well-defined sequence of alternate
997 * names and attempt to use an alternate name instead.
999 * Returns 1 if the (possibly modified) name is not present in the
1000 * name table. Returns 0 if the name and all possible alternates
1001 * are already in the table.
1004 handle_duplicate_name(xfs_dahash_t hash
, size_t name_len
, uchar_t
*name
)
1006 uchar_t new_name
[name_len
+ 1];
1009 if (!nametable_find(hash
, name_len
, name
))
1010 return 1; /* No duplicate */
1012 /* Name is already in use. Need to find an alternate. */
1017 /* Only change incoming name if we find an alternate */
1019 memcpy(new_name
, name
, name_len
);
1020 found
= find_alternate(name_len
, new_name
, seq
++);
1022 return 0; /* No more to check */
1024 } while (nametable_find(hash
, name_len
, new_name
));
1027 * The alternate wasn't in the table already. Pass it back
1030 memcpy(name
, new_name
, name_len
);
1036 generate_obfuscated_name(
1044 * We don't obfuscate "lost+found" or any orphan files
1045 * therein. When the name table is used for extended
1046 * attributes, the inode number provided is 0, in which
1047 * case we don't need to make this check.
1049 if (ino
&& in_lost_found(ino
, namelen
, name
))
1053 * If the name starts with a slash, just skip over it. It
1054 * isn't included in the hash and we don't record it in the
1055 * name table. Note that the namelen value passed in does
1056 * not count the leading slash (if one is present).
1061 /* Obfuscate the name (if possible) */
1063 hash
= libxfs_da_hashname(name
, namelen
);
1064 obfuscate_name(hash
, namelen
, name
);
1067 * Make sure the name is not something already seen. If we
1068 * fail to find a suitable alternate, we're dealing with a
1069 * very pathological situation, and we may end up creating
1070 * a duplicate name in the metadump, so issue a warning.
1072 if (!handle_duplicate_name(hash
, namelen
, name
)) {
1073 print_warning("duplicate name for inode %llu "
1074 "in dir inode %llu\n",
1075 (unsigned long long) ino
,
1076 (unsigned long long) cur_ino
);
1080 /* Create an entry for the new name in the name table. */
1082 if (!nametable_add(hash
, namelen
, name
))
1083 print_warning("unable to record name for inode %llu "
1084 "in dir inode %llu\n",
1085 (unsigned long long) ino
,
1086 (unsigned long long) cur_ino
);
1093 struct xfs_dir2_sf_hdr
*sfp
;
1094 xfs_dir2_sf_entry_t
*sfep
;
1095 __uint64_t ino_dir_size
;
1098 sfp
= (struct xfs_dir2_sf_hdr
*)XFS_DFORK_DPTR(dip
);
1099 ino_dir_size
= be64_to_cpu(dip
->di_size
);
1100 if (ino_dir_size
> XFS_DFORK_DSIZE(dip
, mp
)) {
1101 ino_dir_size
= XFS_DFORK_DSIZE(dip
, mp
);
1103 print_warning("invalid size in dir inode %llu",
1104 (long long)cur_ino
);
1107 sfep
= xfs_dir2_sf_firstentry(sfp
);
1108 for (i
= 0; (i
< sfp
->count
) &&
1109 ((char *)sfep
- (char *)sfp
< ino_dir_size
); i
++) {
1112 * first check for bad name lengths. If they are bad, we
1113 * have limitations to how much can be obfuscated.
1115 int namelen
= sfep
->namelen
;
1119 print_warning("zero length entry in dir inode "
1120 "%llu", (long long)cur_ino
);
1121 if (i
!= sfp
->count
- 1)
1123 namelen
= ino_dir_size
- ((char *)&sfep
->name
[0] -
1125 } else if ((char *)sfep
- (char *)sfp
+
1126 M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
) >
1129 print_warning("entry length in dir inode %llu "
1130 "overflows space", (long long)cur_ino
);
1131 if (i
!= sfp
->count
- 1)
1133 namelen
= ino_dir_size
- ((char *)&sfep
->name
[0] -
1138 generate_obfuscated_name(
1139 M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
),
1140 namelen
, &sfep
->name
[0]);
1142 sfep
= (xfs_dir2_sf_entry_t
*)((char *)sfep
+
1143 M_DIROPS(mp
)->sf_entsize(sfp
, namelen
));
1146 /* zero stale data in rest of space in data fork, if any */
1147 if (zero_stale_data
&& (ino_dir_size
< XFS_DFORK_DSIZE(dip
, mp
)))
1148 memset(sfep
, 0, XFS_DFORK_DSIZE(dip
, mp
) - ino_dir_size
);
1152 * The pathname may not be null terminated. It may be terminated by the end of
1153 * a buffer or inode literal area, and the start of the next region contains
1154 * unknown data. Therefore, when we get to the last component of the symlink, we
1155 * cannot assume that strlen() will give us the right result. Hence we need to
1156 * track the remaining pathname length and use that instead.
1159 obfuscate_path_components(
1163 uchar_t
*comp
= (uchar_t
*)buf
;
1164 uchar_t
*end
= comp
+ len
;
1167 while (comp
< end
) {
1171 /* find slash at end of this component */
1172 slash
= strchr((char *)comp
, '/');
1174 /* last (or single) component */
1175 namelen
= strnlen((char *)comp
, len
);
1176 hash
= libxfs_da_hashname(comp
, namelen
);
1177 obfuscate_name(hash
, namelen
, comp
);
1180 namelen
= slash
- (char *)comp
;
1181 /* handle leading or consecutive slashes */
1187 hash
= libxfs_da_hashname(comp
, namelen
);
1188 obfuscate_name(hash
, namelen
, comp
);
1189 comp
+= namelen
+ 1;
1201 len
= be64_to_cpu(dip
->di_size
);
1202 if (len
> XFS_DFORK_DSIZE(dip
, mp
)) {
1204 print_warning("invalid size (%d) in symlink inode %llu",
1205 len
, (long long)cur_ino
);
1206 len
= XFS_DFORK_DSIZE(dip
, mp
);
1209 buf
= (char *)XFS_DFORK_DPTR(dip
);
1211 obfuscate_path_components(buf
, len
);
1213 /* zero stale data in rest of space in data fork, if any */
1214 if (zero_stale_data
&& len
< XFS_DFORK_DSIZE(dip
, mp
))
1215 memset(&buf
[len
], 0, XFS_DFORK_DSIZE(dip
, mp
) - len
);
1223 * with extended attributes, obfuscate the names and fill the actual
1224 * values with 'v' (to see a valid string length, as opposed to NULLs)
1227 xfs_attr_shortform_t
*asfp
;
1228 xfs_attr_sf_entry_t
*asfep
;
1232 asfp
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
1233 if (asfp
->hdr
.count
== 0)
1236 ino_attr_size
= be16_to_cpu(asfp
->hdr
.totsize
);
1237 if (ino_attr_size
> XFS_DFORK_ASIZE(dip
, mp
)) {
1238 ino_attr_size
= XFS_DFORK_ASIZE(dip
, mp
);
1240 print_warning("invalid attr size in inode %llu",
1241 (long long)cur_ino
);
1244 asfep
= &asfp
->list
[0];
1245 for (i
= 0; (i
< asfp
->hdr
.count
) &&
1246 ((char *)asfep
- (char *)asfp
< ino_attr_size
); i
++) {
1248 int namelen
= asfep
->namelen
;
1252 print_warning("zero length attr entry in inode "
1253 "%llu", (long long)cur_ino
);
1255 } else if ((char *)asfep
- (char *)asfp
+
1256 XFS_ATTR_SF_ENTSIZE(asfep
) > ino_attr_size
) {
1258 print_warning("attr entry length in inode %llu "
1259 "overflows space", (long long)cur_ino
);
1264 generate_obfuscated_name(0, asfep
->namelen
,
1265 &asfep
->nameval
[0]);
1266 memset(&asfep
->nameval
[asfep
->namelen
], 'v',
1270 asfep
= (xfs_attr_sf_entry_t
*)((char *)asfep
+
1271 XFS_ATTR_SF_ENTSIZE(asfep
));
1274 /* zero stale data in rest of space in attr fork, if any */
1275 if (zero_stale_data
&& (ino_attr_size
< XFS_DFORK_ASIZE(dip
, mp
)))
1276 memset(asfep
, 0, XFS_DFORK_ASIZE(dip
, mp
) - ino_attr_size
);
1280 process_dir_data_block(
1282 xfs_fileoff_t offset
,
1283 int is_block_format
)
1286 * we have to rely on the fileoffset and signature of the block to
1287 * handle it's contents. If it's invalid, leave it alone.
1288 * for multi-fsblock dir blocks, if a name crosses an extent boundary,
1289 * ignore it and continue.
1296 struct xfs_dir2_data_hdr
*datahdr
;
1298 datahdr
= (struct xfs_dir2_data_hdr
*)block
;
1300 if (is_block_format
) {
1301 xfs_dir2_leaf_entry_t
*blp
;
1302 xfs_dir2_block_tail_t
*btp
;
1304 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, datahdr
);
1305 blp
= xfs_dir2_block_leaf_p(btp
);
1306 if ((char *)blp
> (char *)btp
)
1307 blp
= (xfs_dir2_leaf_entry_t
*)btp
;
1309 end_of_data
= (char *)blp
- block
;
1310 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1311 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1313 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1314 } else { /* leaf/node format */
1315 end_of_data
= mp
->m_dir_geo
->fsbcount
<< mp
->m_sb
.sb_blocklog
;
1316 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1317 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1319 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1322 if (be32_to_cpu(datahdr
->magic
) != wantmagic
) {
1325 "invalid magic in dir inode %llu block %ld",
1326 (long long)cur_ino
, (long)offset
);
1330 dir_offset
= M_DIROPS(mp
)->data_entry_offset
;
1331 ptr
= block
+ dir_offset
;
1332 endptr
= block
+ mp
->m_dir_geo
->blksize
;
1334 while (ptr
< endptr
&& dir_offset
< end_of_data
) {
1335 xfs_dir2_data_entry_t
*dep
;
1336 xfs_dir2_data_unused_t
*dup
;
1339 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1341 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1342 int length
= be16_to_cpu(dup
->length
);
1343 if (dir_offset
+ length
> end_of_data
||
1344 !length
|| (length
& (XFS_DIR2_DATA_ALIGN
- 1))) {
1347 "invalid length for dir free space in inode %llu",
1348 (long long)cur_ino
);
1351 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1354 dir_offset
+= length
;
1357 * Zero the unused space up to the tag - the tag is
1358 * actually at a variable offset, so zeroing &dup->tag
1359 * is zeroing the free space in between
1361 if (zero_stale_data
) {
1363 sizeof(xfs_dir2_data_unused_t
);
1366 memset(&dup
->tag
, 0, zlen
);
1367 iocur_top
->need_crc
= 1;
1370 if (dir_offset
>= end_of_data
|| ptr
>= endptr
)
1374 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1375 length
= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1377 if (dir_offset
+ length
> end_of_data
||
1378 ptr
+ length
> endptr
) {
1381 "invalid length for dir entry name in inode %llu",
1382 (long long)cur_ino
);
1385 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1390 generate_obfuscated_name(be64_to_cpu(dep
->inumber
),
1391 dep
->namelen
, &dep
->name
[0]);
1392 dir_offset
+= length
;
1394 /* Zero the unused space after name, up to the tag */
1395 if (zero_stale_data
) {
1396 /* 1 byte for ftype; don't bother with conditional */
1398 (char *)M_DIROPS(mp
)->data_entry_tag_p(dep
) -
1399 (char *)&dep
->name
[dep
->namelen
] - 1;
1401 memset(&dep
->name
[dep
->namelen
] + 1, 0, zlen
);
1402 iocur_top
->need_crc
= 1;
1409 process_symlink_block(
1414 if (xfs_sb_version_hascrc(&(mp
)->m_sb
))
1415 link
+= sizeof(struct xfs_dsymlink_hdr
);
1418 obfuscate_path_components(link
, XFS_SYMLINK_BUF_SPACE(mp
,
1419 mp
->m_sb
.sb_blocksize
));
1420 if (zero_stale_data
) {
1421 size_t linklen
, zlen
;
1423 linklen
= strlen(link
);
1424 zlen
= mp
->m_sb
.sb_blocksize
- linklen
;
1425 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1426 zlen
-= sizeof(struct xfs_dsymlink_hdr
);
1427 if (zlen
< mp
->m_sb
.sb_blocksize
)
1428 memset(link
+ linklen
, 0, zlen
);
1432 #define MAX_REMOTE_VALS 4095
1434 static struct attr_data_s
{
1435 int remote_val_count
;
1436 xfs_dablk_t remote_vals
[MAX_REMOTE_VALS
];
1441 xfs_dablk_t blockidx
,
1444 while (length
> 0 && attr_data
.remote_val_count
< MAX_REMOTE_VALS
) {
1445 attr_data
.remote_vals
[attr_data
.remote_val_count
] = blockidx
;
1446 attr_data
.remote_val_count
++;
1448 length
-= mp
->m_sb
.sb_blocksize
;
1451 if (attr_data
.remote_val_count
>= MAX_REMOTE_VALS
) {
1453 "Overflowed attr obfuscation array. No longer obfuscating remote attrs.");
1457 /* Handle remote and leaf attributes */
1461 xfs_fileoff_t offset
)
1463 struct xfs_attr_leafblock
*leaf
;
1464 struct xfs_attr3_icleaf_hdr hdr
;
1467 xfs_attr_leaf_entry_t
*entry
;
1468 xfs_attr_leaf_name_local_t
*local
;
1469 xfs_attr_leaf_name_remote_t
*remote
;
1470 __uint32_t bs
= mp
->m_sb
.sb_blocksize
;
1474 leaf
= (xfs_attr_leafblock_t
*)block
;
1476 /* Remote attributes - attr3 has XFS_ATTR3_RMT_MAGIC, attr has none */
1477 if ((be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
) &&
1478 (be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR3_LEAF_MAGIC
)) {
1479 for (i
= 0; i
< attr_data
.remote_val_count
; i
++) {
1480 if (obfuscate
&& attr_data
.remote_vals
[i
] == offset
)
1481 /* Macros to handle both attr and attr3 */
1483 (bs
- XFS_ATTR3_RMT_BUF_SPACE(mp
, bs
)),
1484 'v', XFS_ATTR3_RMT_BUF_SPACE(mp
, bs
));
1489 /* Ok, it's a leaf - get header; accounts for crc & non-crc */
1490 xfs_attr3_leaf_hdr_from_disk(mp
->m_attr_geo
, &hdr
, leaf
);
1492 nentries
= hdr
.count
;
1493 if (nentries
* sizeof(xfs_attr_leaf_entry_t
) +
1494 xfs_attr3_leaf_hdr_size(leaf
) >
1495 XFS_ATTR3_RMT_BUF_SPACE(mp
, bs
)) {
1497 print_warning("invalid attr count in inode %llu",
1498 (long long)cur_ino
);
1502 entry
= xfs_attr3_leaf_entryp(leaf
);
1503 /* We will move this as we parse */
1505 for (i
= 0; i
< nentries
; i
++, entry
++) {
1506 int nlen
, vlen
, zlen
;
1508 /* Grows up; if this name is topmost, move first_name */
1509 if (!first_name
|| xfs_attr3_leaf_name(leaf
, i
) < first_name
)
1510 first_name
= xfs_attr3_leaf_name(leaf
, i
);
1512 if (be16_to_cpu(entry
->nameidx
) > mp
->m_sb
.sb_blocksize
) {
1515 "invalid attr nameidx in inode %llu",
1516 (long long)cur_ino
);
1519 if (entry
->flags
& XFS_ATTR_LOCAL
) {
1520 local
= xfs_attr3_leaf_name_local(leaf
, i
);
1521 if (local
->namelen
== 0) {
1524 "zero length for attr name in inode %llu",
1525 (long long)cur_ino
);
1529 generate_obfuscated_name(0, local
->namelen
,
1530 &local
->nameval
[0]);
1531 memset(&local
->nameval
[local
->namelen
], 'v',
1532 be16_to_cpu(local
->valuelen
));
1534 /* zero from end of nameval[] to next name start */
1535 nlen
= local
->namelen
;
1536 vlen
= be16_to_cpu(local
->valuelen
);
1537 zlen
= xfs_attr_leaf_entsize_local(nlen
, vlen
) -
1538 (sizeof(xfs_attr_leaf_name_local_t
) - 1 +
1540 if (zero_stale_data
)
1541 memset(&local
->nameval
[nlen
+ vlen
], 0, zlen
);
1543 remote
= xfs_attr3_leaf_name_remote(leaf
, i
);
1544 if (remote
->namelen
== 0 || remote
->valueblk
== 0) {
1547 "invalid attr entry in inode %llu",
1548 (long long)cur_ino
);
1552 generate_obfuscated_name(0, remote
->namelen
,
1554 add_remote_vals(be32_to_cpu(remote
->valueblk
),
1555 be32_to_cpu(remote
->valuelen
));
1557 /* zero from end of name[] to next name start */
1558 nlen
= remote
->namelen
;
1559 zlen
= xfs_attr_leaf_entsize_remote(nlen
) -
1560 (sizeof(xfs_attr_leaf_name_remote_t
) - 1 +
1562 if (zero_stale_data
)
1563 memset(&remote
->name
[nlen
], 0, zlen
);
1567 /* Zero from end of entries array to the first name/val */
1568 if (zero_stale_data
) {
1569 struct xfs_attr_leaf_entry
*entries
;
1571 entries
= xfs_attr3_leaf_entryp(leaf
);
1572 memset(&entries
[nentries
], 0,
1573 first_name
- (char *)&entries
[nentries
]);
1577 /* Processes symlinks, attrs, directories ... */
1579 process_single_fsb_objects(
1590 for (i
= 0; i
< c
; i
++) {
1592 set_cur(&typtab
[btype
], XFS_FSB_TO_DADDR(mp
, s
), blkbb
,
1595 if (!iocur_top
->data
) {
1596 xfs_agnumber_t agno
= XFS_FSB_TO_AGNO(mp
, s
);
1597 xfs_agblock_t agbno
= XFS_FSB_TO_AGBNO(mp
, s
);
1599 print_warning("cannot read %s block %u/%u (%llu)",
1600 typtab
[btype
].name
, agno
, agbno
, s
);
1601 if (stop_on_read_error
)
1607 if (!obfuscate
&& !zero_stale_data
)
1610 /* Zero unused part of interior nodes */
1611 if (zero_stale_data
) {
1612 xfs_da_intnode_t
*node
= iocur_top
->data
;
1613 int magic
= be16_to_cpu(node
->hdr
.info
.magic
);
1615 if (magic
== XFS_DA_NODE_MAGIC
||
1616 magic
== XFS_DA3_NODE_MAGIC
) {
1617 struct xfs_da3_icnode_hdr hdr
;
1620 M_DIROPS(mp
)->node_hdr_from_disk(&hdr
, node
);
1621 used
= M_DIROPS(mp
)->node_hdr_size
;
1624 * sizeof(struct xfs_da_node_entry
);
1626 if (used
< mp
->m_sb
.sb_blocksize
) {
1627 memset((char *)node
+ used
, 0,
1628 mp
->m_sb
.sb_blocksize
- used
);
1629 iocur_top
->need_crc
= 1;
1634 /* Handle leaf nodes */
1635 dp
= iocur_top
->data
;
1638 if (o
>= mp
->m_dir_geo
->leafblk
)
1641 process_dir_data_block(dp
, o
,
1642 last
== mp
->m_dir_geo
->fsbcount
);
1643 iocur_top
->need_crc
= 1;
1646 process_symlink_block(dp
);
1647 iocur_top
->need_crc
= 1;
1650 process_attr_block(dp
, o
);
1651 iocur_top
->need_crc
= 1;
1658 ret
= write_buf(iocur_top
);
1671 * Static map to aggregate multiple extents into a single directory block.
1673 static struct bbmap mfsb_map
;
1674 static int mfsb_length
;
1677 process_multi_fsb_objects(
1690 print_warning("bad type for multi-fsb object %d", btype
);
1695 unsigned int bm_len
;
1697 if (mfsb_length
+ c
>= mp
->m_dir_geo
->fsbcount
) {
1698 bm_len
= mp
->m_dir_geo
->fsbcount
- mfsb_length
;
1705 mfsb_map
.b
[mfsb_map
.nmaps
].bm_bn
= XFS_FSB_TO_DADDR(mp
, s
);
1706 mfsb_map
.b
[mfsb_map
.nmaps
].bm_len
= XFS_FSB_TO_BB(mp
, bm_len
);
1709 if (mfsb_length
== 0) {
1711 set_cur(&typtab
[btype
], 0, 0, DB_RING_IGN
, &mfsb_map
);
1712 if (!iocur_top
->data
) {
1713 xfs_agnumber_t agno
= XFS_FSB_TO_AGNO(mp
, s
);
1714 xfs_agblock_t agbno
= XFS_FSB_TO_AGBNO(mp
, s
);
1716 print_warning("cannot read %s block %u/%u (%llu)",
1717 typtab
[btype
].name
, agno
, agbno
, s
);
1718 if (stop_on_read_error
)
1724 if ((!obfuscate
&& !zero_stale_data
) ||
1725 o
>= mp
->m_dir_geo
->leafblk
) {
1726 ret
= write_buf(iocur_top
);
1730 process_dir_data_block(iocur_top
->data
, o
,
1731 last
== mp
->m_dir_geo
->fsbcount
);
1732 iocur_top
->need_crc
= 1;
1733 ret
= write_buf(iocur_top
);
1747 /* inode copy routines */
1749 process_bmbt_reclist(
1755 xfs_fileoff_t o
, op
= NULLFILEOFF
;
1757 xfs_filblks_t c
, cp
= NULLFILEOFF
;
1760 xfs_agnumber_t agno
;
1761 xfs_agblock_t agbno
;
1764 if (btype
== TYP_DATA
)
1767 convert_extent(&rp
[numrecs
- 1], &o
, &s
, &c
, &f
);
1770 for (i
= 0; i
< numrecs
; i
++, rp
++) {
1771 convert_extent(rp
, &o
, &s
, &c
, &f
);
1774 * ignore extents that are clearly bogus, and if a bogus
1775 * one is found, stop processing remaining extents
1777 if (i
> 0 && op
+ cp
> o
) {
1779 print_warning("bmap extent %d in %s ino %llu "
1780 "starts at %llu, previous extent "
1782 typtab
[btype
].name
, (long long)cur_ino
,
1787 if (c
> max_extent_size
) {
1789 * since we are only processing non-data extents,
1790 * large numbers of blocks in a metadata extent is
1791 * extremely rare and more than likely to be corrupt.
1794 print_warning("suspicious count %u in bmap "
1795 "extent %d in %s ino %llu", c
, i
,
1796 typtab
[btype
].name
, (long long)cur_ino
);
1803 agno
= XFS_FSB_TO_AGNO(mp
, s
);
1804 agbno
= XFS_FSB_TO_AGBNO(mp
, s
);
1806 if (!valid_bno(agno
, agbno
)) {
1808 print_warning("invalid block number %u/%u "
1809 "(%llu) in bmap extent %d in %s ino "
1810 "%llu", agno
, agbno
, s
, i
,
1811 typtab
[btype
].name
, (long long)cur_ino
);
1815 if (!valid_bno(agno
, agbno
+ c
- 1)) {
1817 print_warning("bmap extent %i in %s inode %llu "
1818 "overflows AG (end is %u/%u)", i
,
1819 typtab
[btype
].name
, (long long)cur_ino
,
1820 agno
, agbno
+ c
- 1);
1824 /* multi-extent blocks require special handling */
1825 if (btype
!= TYP_DIR2
|| mp
->m_dir_geo
->fsbcount
== 1) {
1826 error
= process_single_fsb_objects(o
, s
, c
, btype
, last
);
1828 error
= process_multi_fsb_objects(o
, s
, c
, btype
, last
);
1839 struct xfs_btree_block
*block
,
1840 xfs_agnumber_t agno
,
1841 xfs_agblock_t agbno
,
1844 void *arg
) /* ptr to itype */
1850 nrecs
= be16_to_cpu(block
->bb_numrecs
);
1853 if (nrecs
> mp
->m_bmap_dmxr
[0]) {
1855 print_warning("invalid numrecs (%u) in %s "
1856 "block %u/%u", nrecs
,
1857 typtab
[btype
].name
, agno
, agbno
);
1860 return process_bmbt_reclist(XFS_BMBT_REC_ADDR(mp
, block
, 1),
1861 nrecs
, *(typnm_t
*)arg
);
1864 if (nrecs
> mp
->m_bmap_dmxr
[1]) {
1866 print_warning("invalid numrecs (%u) in %s block %u/%u",
1867 nrecs
, typtab
[btype
].name
, agno
, agbno
);
1870 pp
= XFS_BMBT_PTR_ADDR(mp
, block
, 1, mp
->m_bmap_dmxr
[1]);
1871 for (i
= 0; i
< nrecs
; i
++) {
1875 ag
= XFS_FSB_TO_AGNO(mp
, be64_to_cpu(pp
[i
]));
1876 bno
= XFS_FSB_TO_AGBNO(mp
, be64_to_cpu(pp
[i
]));
1878 if (bno
== 0 || bno
> mp
->m_sb
.sb_agblocks
||
1879 ag
> mp
->m_sb
.sb_agcount
) {
1881 print_warning("invalid block number (%u/%u) "
1882 "in %s block %u/%u", ag
, bno
,
1883 typtab
[btype
].name
, agno
, agbno
);
1887 if (!scan_btree(ag
, bno
, level
, btype
, arg
, scanfunc_bmap
))
1898 xfs_bmdr_block_t
*dib
;
1907 whichfork
= (itype
== TYP_ATTR
) ? XFS_ATTR_FORK
: XFS_DATA_FORK
;
1908 btype
= (itype
== TYP_ATTR
) ? TYP_BMAPBTA
: TYP_BMAPBTD
;
1910 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
1911 level
= be16_to_cpu(dib
->bb_level
);
1912 nrecs
= be16_to_cpu(dib
->bb_numrecs
);
1914 if (level
> XFS_BM_MAXLEVELS(mp
, whichfork
)) {
1916 print_warning("invalid level (%u) in inode %lld %s "
1917 "root", level
, (long long)cur_ino
,
1918 typtab
[btype
].name
);
1923 return process_bmbt_reclist(XFS_BMDR_REC_ADDR(dib
, 1),
1927 maxrecs
= xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0);
1928 if (nrecs
> maxrecs
) {
1930 print_warning("invalid numrecs (%u) in inode %lld %s "
1931 "root", nrecs
, (long long)cur_ino
,
1932 typtab
[btype
].name
);
1936 pp
= XFS_BMDR_PTR_ADDR(dib
, 1, maxrecs
);
1937 for (i
= 0; i
< nrecs
; i
++) {
1941 ag
= XFS_FSB_TO_AGNO(mp
, be64_to_cpu(pp
[i
]));
1942 bno
= XFS_FSB_TO_AGBNO(mp
, be64_to_cpu(pp
[i
]));
1944 if (bno
== 0 || bno
> mp
->m_sb
.sb_agblocks
||
1945 ag
> mp
->m_sb
.sb_agcount
) {
1947 print_warning("invalid block number (%u/%u) "
1948 "in inode %llu %s root", ag
,
1949 bno
, (long long)cur_ino
,
1950 typtab
[btype
].name
);
1954 if (!scan_btree(ag
, bno
, level
, btype
, &itype
, scanfunc_bmap
))
1969 whichfork
= (itype
== TYP_ATTR
) ? XFS_ATTR_FORK
: XFS_DATA_FORK
;
1971 nex
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
1972 used
= nex
* sizeof(xfs_bmbt_rec_t
);
1973 if (nex
< 0 || used
> XFS_DFORK_SIZE(dip
, mp
, whichfork
)) {
1975 print_warning("bad number of extents %d in inode %lld",
1976 nex
, (long long)cur_ino
);
1980 /* Zero unused data fork past used extents */
1981 if (zero_stale_data
&& (used
< XFS_DFORK_SIZE(dip
, mp
, whichfork
)))
1982 memset(XFS_DFORK_PTR(dip
, whichfork
) + used
, 0,
1983 XFS_DFORK_SIZE(dip
, mp
, whichfork
) - used
);
1986 return process_bmbt_reclist((xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
,
1987 whichfork
), nex
, itype
);
1995 switch (dip
->di_format
) {
1996 case XFS_DINODE_FMT_LOCAL
:
1997 if (obfuscate
|| zero_stale_data
)
2000 process_sf_dir(dip
);
2004 process_sf_symlink(dip
);
2011 case XFS_DINODE_FMT_EXTENTS
:
2012 return process_exinode(dip
, itype
);
2014 case XFS_DINODE_FMT_BTREE
:
2015 return process_btinode(dip
, itype
);
2021 * when we process the inode, we may change the data in the data and/or
2022 * attribute fork if they are in short form and we are obfuscating names.
2023 * In this case we need to recalculate the CRC of the inode, but we should
2024 * only do that if the CRC in the inode is good to begin with. If the crc
2025 * is not ok, we just leave it alone.
2029 xfs_agnumber_t agno
,
2035 bool crc_was_ok
= false; /* no recalc by default */
2036 bool need_new_crc
= false;
2039 cur_ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
2041 /* we only care about crc recalculation if we will modify the inode. */
2042 if (obfuscate
|| zero_stale_data
) {
2043 crc_was_ok
= xfs_verify_cksum((char *)dip
,
2044 mp
->m_sb
.sb_inodesize
,
2045 offsetof(struct xfs_dinode
, di_crc
));
2049 if (zero_stale_data
) {
2050 /* Zero all of the inode literal area */
2051 memset(XFS_DFORK_DPTR(dip
), 0,
2052 XFS_LITINO(mp
, dip
->di_version
));
2057 /* copy appropriate data fork metadata */
2058 switch (be16_to_cpu(dip
->di_mode
) & S_IFMT
) {
2060 success
= process_inode_data(dip
, TYP_DIR2
);
2061 if (dip
->di_format
== XFS_DINODE_FMT_LOCAL
)
2065 success
= process_inode_data(dip
, TYP_SYMLINK
);
2066 if (dip
->di_format
== XFS_DINODE_FMT_LOCAL
)
2070 success
= process_inode_data(dip
, TYP_DATA
);
2076 /* copy extended attributes if they exist and forkoff is valid */
2078 XFS_DFORK_DSIZE(dip
, mp
) < XFS_LITINO(mp
, dip
->di_version
)) {
2079 attr_data
.remote_val_count
= 0;
2080 switch (dip
->di_aformat
) {
2081 case XFS_DINODE_FMT_LOCAL
:
2083 if (obfuscate
|| zero_stale_data
)
2084 process_sf_attr(dip
);
2087 case XFS_DINODE_FMT_EXTENTS
:
2088 success
= process_exinode(dip
, TYP_ATTR
);
2091 case XFS_DINODE_FMT_BTREE
:
2092 success
= process_btinode(dip
, TYP_ATTR
);
2099 /* Heavy handed but low cost; just do it as a catch-all. */
2100 if (zero_stale_data
)
2103 if (crc_was_ok
&& need_new_crc
)
2104 libxfs_dinode_calc_crc(mp
, dip
);
2108 static __uint32_t inodes_copied
= 0;
2112 xfs_agnumber_t agno
,
2113 xfs_inobt_rec_t
*rp
)
2117 xfs_agblock_t agbno
;
2118 xfs_agblock_t end_agbno
;
2125 agino
= be32_to_cpu(rp
->ir_startino
);
2126 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
2127 end_agbno
= agbno
+ mp
->m_ialloc_blks
;
2128 off
= XFS_INO_TO_OFFSET(mp
, agino
);
2131 * If the fs supports sparse inode records, we must process inodes a
2132 * cluster at a time because that is the sparse allocation granularity.
2133 * Otherwise, we risk CRC corruption errors on reads of inode chunks.
2135 * Also make sure that that we don't process more than the single record
2136 * we've been passed (large block sizes can hold multiple inode chunks).
2138 if (xfs_sb_version_hassparseinodes(&mp
->m_sb
))
2139 blks_per_buf
= xfs_icluster_size_fsb(mp
);
2141 blks_per_buf
= mp
->m_ialloc_blks
;
2142 inodes_per_buf
= min(blks_per_buf
<< mp
->m_sb
.sb_inopblog
,
2143 XFS_INODES_PER_CHUNK
);
2146 * Sanity check that we only process a single buffer if ir_startino has
2147 * a buffer offset. A non-zero offset implies that the entire chunk lies
2150 if (off
&& inodes_per_buf
!= XFS_INODES_PER_CHUNK
) {
2151 print_warning("bad starting inode offset %d", off
);
2155 if (agino
== 0 || agino
== NULLAGINO
|| !valid_bno(agno
, agbno
) ||
2156 !valid_bno(agno
, XFS_AGINO_TO_AGBNO(mp
,
2157 agino
+ XFS_INODES_PER_CHUNK
- 1))) {
2159 print_warning("bad inode number %llu (%u/%u)",
2160 XFS_AGINO_TO_INO(mp
, agno
, agino
), agno
, agino
);
2165 * check for basic assumptions about inode chunks, and if any
2166 * assumptions fail, don't process the inode chunk.
2168 if ((mp
->m_sb
.sb_inopblock
<= XFS_INODES_PER_CHUNK
&& off
!= 0) ||
2169 (mp
->m_sb
.sb_inopblock
> XFS_INODES_PER_CHUNK
&&
2170 off
% XFS_INODES_PER_CHUNK
!= 0) ||
2171 (xfs_sb_version_hasalign(&mp
->m_sb
) &&
2172 mp
->m_sb
.sb_inoalignmt
!= 0 &&
2173 agbno
% mp
->m_sb
.sb_inoalignmt
!= 0)) {
2175 print_warning("badly aligned inode (start = %llu)",
2176 XFS_AGINO_TO_INO(mp
, agno
, agino
));
2182 while (agbno
< end_agbno
&& ioff
< XFS_INODES_PER_CHUNK
) {
2183 if (xfs_inobt_is_sparse_disk(rp
, ioff
))
2186 set_cur(&typtab
[TYP_INODE
], XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
2187 XFS_FSB_TO_BB(mp
, blks_per_buf
), DB_RING_IGN
, NULL
);
2188 if (iocur_top
->data
== NULL
) {
2189 print_warning("cannot read inode block %u/%u",
2191 rval
= !stop_on_read_error
;
2195 for (i
= 0; i
< inodes_per_buf
; i
++) {
2198 dip
= (xfs_dinode_t
*)((char *)iocur_top
->data
+
2199 ((off
+ i
) << mp
->m_sb
.sb_inodelog
));
2201 /* process_inode handles free inodes, too */
2202 if (!process_inode(agno
, agino
+ ioff
+ i
, dip
,
2203 XFS_INOBT_IS_FREE_DISK(rp
, i
)))
2209 if (write_buf(iocur_top
))
2213 agbno
+= blks_per_buf
;
2214 ioff
+= inodes_per_buf
;
2218 print_progress("Copied %u of %u inodes (%u of %u AGs)",
2219 inodes_copied
, mp
->m_sb
.sb_icount
, agno
,
2220 mp
->m_sb
.sb_agcount
);
2229 struct xfs_btree_block
*block
,
2230 xfs_agnumber_t agno
,
2231 xfs_agblock_t agbno
,
2236 xfs_inobt_rec_t
*rp
;
2237 xfs_inobt_ptr_t
*pp
;
2240 int finobt
= *(int *) arg
;
2242 numrecs
= be16_to_cpu(block
->bb_numrecs
);
2245 if (numrecs
> mp
->m_inobt_mxr
[0]) {
2247 print_warning("invalid numrecs %d in %s "
2248 "block %u/%u", numrecs
,
2249 typtab
[btype
].name
, agno
, agbno
);
2250 numrecs
= mp
->m_inobt_mxr
[0];
2254 * Only copy the btree blocks for the finobt. The inobt scan
2255 * copies the inode chunks.
2260 rp
= XFS_INOBT_REC_ADDR(mp
, block
, 1);
2261 for (i
= 0; i
< numrecs
; i
++, rp
++) {
2262 if (!copy_inode_chunk(agno
, rp
))
2268 if (numrecs
> mp
->m_inobt_mxr
[1]) {
2270 print_warning("invalid numrecs %d in %s block %u/%u",
2271 numrecs
, typtab
[btype
].name
, agno
, agbno
);
2272 numrecs
= mp
->m_inobt_mxr
[1];
2275 pp
= XFS_INOBT_PTR_ADDR(mp
, block
, 1, mp
->m_inobt_mxr
[1]);
2276 for (i
= 0; i
< numrecs
; i
++) {
2277 if (!valid_bno(agno
, be32_to_cpu(pp
[i
]))) {
2279 print_warning("invalid block number (%u/%u) "
2280 "in %s block %u/%u",
2281 agno
, be32_to_cpu(pp
[i
]),
2282 typtab
[btype
].name
, agno
, agbno
);
2285 if (!scan_btree(agno
, be32_to_cpu(pp
[i
]), level
,
2286 btype
, arg
, scanfunc_ino
))
2294 xfs_agnumber_t agno
,
2301 root
= be32_to_cpu(agi
->agi_root
);
2302 levels
= be32_to_cpu(agi
->agi_level
);
2304 /* validate root and levels before processing the tree */
2305 if (root
== 0 || root
> mp
->m_sb
.sb_agblocks
) {
2307 print_warning("invalid block number (%u) in inobt "
2308 "root in agi %u", root
, agno
);
2311 if (levels
>= XFS_BTREE_MAXLEVELS
) {
2313 print_warning("invalid level (%u) in inobt root "
2314 "in agi %u", levels
, agno
);
2318 if (!scan_btree(agno
, root
, levels
, TYP_INOBT
, &finobt
, scanfunc_ino
))
2321 if (xfs_sb_version_hasfinobt(&mp
->m_sb
)) {
2322 root
= be32_to_cpu(agi
->agi_free_root
);
2323 levels
= be32_to_cpu(agi
->agi_free_level
);
2326 if (!scan_btree(agno
, root
, levels
, TYP_INOBT
, &finobt
,
2336 xfs_agnumber_t agno
)
2340 int stack_count
= 0;
2343 /* copy the superblock of the AG */
2346 set_cur(&typtab
[TYP_SB
], XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
2347 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
2348 if (!iocur_top
->data
) {
2349 print_warning("cannot read superblock for ag %u", agno
);
2350 if (stop_on_read_error
)
2353 /* Replace any filesystem label with "L's" */
2355 struct xfs_sb
*sb
= iocur_top
->data
;
2356 memset(sb
->sb_fname
, 'L',
2357 min(strlen(sb
->sb_fname
), sizeof(sb
->sb_fname
)));
2358 iocur_top
->need_crc
= 1;
2360 if (write_buf(iocur_top
))
2364 /* copy the AG free space btree root */
2367 set_cur(&typtab
[TYP_AGF
], XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
2368 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
2369 agf
= iocur_top
->data
;
2370 if (iocur_top
->data
== NULL
) {
2371 print_warning("cannot read agf block for ag %u", agno
);
2372 if (stop_on_read_error
)
2375 if (write_buf(iocur_top
))
2379 /* copy the AG inode btree root */
2382 set_cur(&typtab
[TYP_AGI
], XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
2383 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
2384 agi
= iocur_top
->data
;
2385 if (iocur_top
->data
== NULL
) {
2386 print_warning("cannot read agi block for ag %u", agno
);
2387 if (stop_on_read_error
)
2390 if (write_buf(iocur_top
))
2394 /* copy the AG free list header */
2397 set_cur(&typtab
[TYP_AGFL
], XFS_AG_DADDR(mp
, agno
, XFS_AGFL_DADDR(mp
)),
2398 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
2399 if (iocur_top
->data
== NULL
) {
2400 print_warning("cannot read agfl block for ag %u", agno
);
2401 if (stop_on_read_error
)
2404 if (agf
&& zero_stale_data
) {
2405 /* Zero out unused bits of agfl */
2409 agfl_bno
= XFS_BUF_TO_AGFL_BNO(mp
, iocur_top
->bp
);
2410 i
= be32_to_cpu(agf
->agf_fllast
);
2413 if (++i
== XFS_AGFL_SIZE(mp
))
2415 if (i
== be32_to_cpu(agf
->agf_flfirst
))
2417 agfl_bno
[i
] = cpu_to_be32(NULLAGBLOCK
);
2419 iocur_top
->need_crc
= 1;
2421 if (write_buf(iocur_top
))
2425 /* copy AG free space btrees */
2428 print_progress("Copying free space trees of AG %u",
2430 if (!copy_free_bno_btree(agno
, agf
))
2432 if (!copy_free_cnt_btree(agno
, agf
))
2436 /* copy inode btrees and the inodes and their associated metadata */
2438 if (!copy_inodes(agno
, agi
))
2443 while (stack_count
--)
2453 xfs_agnumber_t agno
;
2454 xfs_agblock_t agbno
;
2459 if (ino
== 0 || ino
== NULLFSINO
)
2462 agno
= XFS_INO_TO_AGNO(mp
, ino
);
2463 agino
= XFS_INO_TO_AGINO(mp
, ino
);
2464 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
2465 offset
= XFS_AGINO_TO_OFFSET(mp
, agino
);
2467 if (agno
>= mp
->m_sb
.sb_agcount
|| agbno
>= mp
->m_sb
.sb_agblocks
||
2468 offset
>= mp
->m_sb
.sb_inopblock
) {
2470 print_warning("invalid %s inode number (%lld)",
2471 typtab
[itype
].name
, (long long)ino
);
2476 set_cur(&typtab
[TYP_INODE
], XFS_AGB_TO_DADDR(mp
, agno
, agbno
),
2477 blkbb
, DB_RING_IGN
, NULL
);
2478 if (iocur_top
->data
== NULL
) {
2479 print_warning("cannot read %s inode %lld",
2480 typtab
[itype
].name
, (long long)ino
);
2481 rval
= !stop_on_read_error
;
2484 off_cur(offset
<< mp
->m_sb
.sb_inodelog
, mp
->m_sb
.sb_inodesize
);
2487 rval
= process_inode_data(iocur_top
->data
, itype
);
2495 copy_sb_inodes(void)
2497 if (!copy_ino(mp
->m_sb
.sb_rbmino
, TYP_RTBITMAP
))
2500 if (!copy_ino(mp
->m_sb
.sb_rsumino
, TYP_RTSUMMARY
))
2503 if (!copy_ino(mp
->m_sb
.sb_uquotino
, TYP_DQBLK
))
2506 if (!copy_ino(mp
->m_sb
.sb_gquotino
, TYP_DQBLK
))
2509 return copy_ino(mp
->m_sb
.sb_pquotino
, TYP_DQBLK
);
2518 print_progress("Copying log");
2521 set_cur(&typtab
[TYP_LOG
], XFS_FSB_TO_DADDR(mp
, mp
->m_sb
.sb_logstart
),
2522 mp
->m_sb
.sb_logblocks
* blkbb
, DB_RING_IGN
, NULL
);
2523 if (iocur_top
->data
== NULL
) {
2525 print_warning("cannot read log");
2526 return !stop_on_read_error
;
2529 /* If not obfuscating or zeroing, just copy the log as it is */
2530 if (!obfuscate
&& !zero_stale_data
)
2533 dirty
= xlog_is_dirty(mp
, &x
, 0);
2537 /* clear out a clean log */
2539 print_progress("Zeroing clean log");
2540 memset(iocur_top
->data
, 0,
2541 mp
->m_sb
.sb_logblocks
* mp
->m_sb
.sb_blocksize
);
2544 /* keep the dirty log */
2546 _("Filesystem log is dirty; image will contain unobfuscated metadata in log."));
2549 /* log detection error */
2551 _("Could not discern log; image will contain unobfuscated metadata in log."));
2556 return !write_buf(iocur_top
);
2564 xfs_agnumber_t agno
;
2572 stop_on_read_error
= 0;
2574 if (mp
->m_sb
.sb_magicnum
!= XFS_SB_MAGIC
) {
2575 print_warning("bad superblock magic number %x, giving up",
2576 mp
->m_sb
.sb_magicnum
);
2580 while ((c
= getopt(argc
, argv
, "aegm:ow")) != EOF
) {
2583 zero_stale_data
= 0;
2586 stop_on_read_error
= 1;
2592 max_extent_size
= (int)strtol(optarg
, &p
, 0);
2593 if (*p
!= '\0' || max_extent_size
<= 0) {
2594 print_warning("bad max extent size %s",
2606 print_warning("bad option for metadump command");
2611 if (optind
!= argc
- 1) {
2612 print_warning("too few options for metadump (no filename given)");
2616 metablock
= (xfs_metablock_t
*)calloc(BBSIZE
+ 1, BBSIZE
);
2617 if (metablock
== NULL
) {
2618 print_warning("memory allocation failure");
2621 metablock
->mb_blocklog
= BBSHIFT
;
2622 metablock
->mb_magic
= cpu_to_be32(XFS_MD_MAGIC
);
2624 block_index
= (__be64
*)((char *)metablock
+ sizeof(xfs_metablock_t
));
2625 block_buffer
= (char *)metablock
+ BBSIZE
;
2626 num_indicies
= (BBSIZE
- sizeof(xfs_metablock_t
)) / sizeof(__be64
);
2628 start_iocur_sp
= iocur_sp
;
2630 if (strcmp(argv
[optind
], "-") == 0) {
2631 if (isatty(fileno(stdout
))) {
2632 print_warning("cannot write to a terminal");
2638 outf
= fopen(argv
[optind
], "wb");
2640 print_warning("cannot create dump file");
2648 for (agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++) {
2649 if (!scan_ag(agno
)) {
2655 /* copy realtime and quota inode contents */
2657 exitcode
= !copy_sb_inodes();
2659 /* copy log if it's internal */
2660 if ((mp
->m_sb
.sb_logstart
!= 0) && !exitcode
)
2661 exitcode
= !copy_log();
2663 /* write the remaining index */
2665 exitcode
= write_index() < 0;
2667 if (progress_since_warning
)
2668 fputc('\n', (outf
== stdout
) ? stderr
: stdout
);
2673 /* cleanup iocur stack */
2674 while (iocur_sp
> start_iocur_sp
)