Debian Codegraph @

faketape/dump-info.cpp

raw symbols SCIP
1 /*
2 * Copyright (c) 2024
3 * Tim Woodall. All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 * SPDX short identifier: BSD-2-Clause
28 */
29
30 /*
31 * dump-info - start of a tool to dump the information on a dump tape for
32 * debugging purposes
33 */
34
35 #include "config.h" // IWYU pragma: keep
36 #include "faketape-lib.h"
37
38 #include "bswap_header.h"
39
40 #include <inttypes.h>
41 #include <sys/types.h>
42 #include <iostream>
43 #include <vector>
44 #include <unordered_map>
45 #include <cstring>
46 #include <sys/stat.h>
47 #include <fcntl.h>
48 #include <err.h>
49 #include <unistd.h>
50 #include <getopt.h>
51 #include <zlib.h>
52 #include <bzlib.h>
53 #include <lzo/lzo1x.h>
54 #include <ext2fs/ext2_fs.h>
55 #include <ext2fs/ext2_ext_attr.h>
56 #include <optional>
57 #include <endian.h>
58 #include <lzo/lzoconf.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <zconf.h>
62 #include <algorithm>
63 #include <memory>
64 #include <string>
65 #include <string_view>
66
67 // Messy. Ideally we'd use readblock_tape from restore/readtape.c but there are
68 // too many issues with global variables that we don't use but need to link in.
69
70 // Manually copied from protocols/dumprestore.h
71 #define ROOTINO EXT2_ROOT_INO
72
73 /*
74 * extattributes inode info
75 */
76 #define EXT_REGULAR 0
77 #define EXT_MACOSFNDRINFO 1
78 #define EXT_MACOSRESFORK 2
79 #define EXT_XATTR 3
80
81 #define COMPRESS_ZLIB 0
82 #define COMPRESS_BZLIB 1
83 #define COMPRESS_LZO 2
84
85 std::string convert_type(uint32_t type) {
86 #define C(X) case X: return std::string(#X " ").substr(0,8); break
87 switch (type) {
88 C(TS_TAPE);
89 C(TS_INODE);
90 C(TS_ADDR);
91 C(TS_BITS);
92 C(TS_CLRI);
93 C(TS_END);
94 default:
95 return "unknown " + std::to_string(type);
96 }
97 #undef C
98 }
99
100 std::string convert_flags(int32_t flags) {
101 #define C(X) if(flags&(X)) { ret += "|" #X; flags &= ~(X); }
102 std::string ret;
103 C(DR_NEWHEADER);
104 C(DR_NEWINODEFMT);
105 C(DR_COMPRESSED);
106 C(DR_METAONLY);
107 C(DR_EXTATTRIBUTES);
108 if (flags)
109 ret += "|" + std::to_string(flags);
110 if(ret.size())
111 return ret.substr(1);
112 return "0";
113 #undef C
114 }
115
116 static std::vector<uint8_t> databuffer;
117
118 [[noreturn]] void usage(const char* prog, int exitcode) {
119 auto wrap = [](const std::string& p1, const std::string& msg) {
120 std::string m = p1 + msg;
121 while (true) {
122 auto sp = std::min(m.find("\n"), m.find(" ", 70));
123 if (sp == std::string::npos) {
124 std::cerr << m << std::endl;
125 return;
126 }
127 std::cerr << m.substr(0, sp) << std::endl;
128 m = p1 + m.substr(sp+1);
129 }
130 };
131
132 std::cerr << "Usage " << prog << " dump-img" << std::endl;
133 std::cerr << " -e, --zero-ea-padding" << std::endl;
134 std::cerr << " -p, --zero-directory-padding" << std::endl;
135 std::cerr << " -s, --zero-symlink-padding" << std::endl;
136 wrap(" ",
137 "older versions of dump used to write uninitialized data "
138 "beyond the end of the data from the inode. These three "
139 "flags cause dump-info to zero these bytes before "
140 "calculating the crc for the block");
141 std::cerr << " -m, --print-header" << std::endl;
142 wrap(" ",
143 "print out the detailed information in the dump header block "
144 "for the inode. Note that this is done after normalization if "
145 "--normalize-header is also used.");
146 std::cerr << " -n, --normalize-header" << std::endl;
147 wrap(" ",
148 "zero out the bytes in the dump header block for the inode "
149 "that are expected differ between dumps of the same fs before "
150 "calculating the crc.\nThis also zeros out the h_checksum in "
151 "any ext2_ext_attr_header.");
152 std::cerr << " -i, --normalize-inodes" << std::endl;
153 wrap(" ",
154 "Normalize inodes so that they are assigned in the order "
155 "they're seen in the dump rather than whatever numbers they "
156 "got in real life. Note that this will only work reliably "
157 "where directory inodes are found in order");
158 std::cerr << " -v, --version" << std::endl;
159 std::cerr << " -d, --debug" << std::endl;
160 exit(exitcode);
161 }
162
163 [[noreturn]] void fatal(const char* msg, const char* prog) {
164 std::cerr << "FATAL: " << msg << std::endl << std::endl;
165 usage(prog, 1);
166 }
167
168 std::string getmode(uint16_t mode) {
169 std::string result;
170 if (mode & S_ISUID) result += 'r'; else result += '-';
171
172 if (mode & S_IRUSR) result += 'r'; else result += '-';
173 if (mode & S_IWUSR) result += 'w'; else result += '-';
174 if (mode & S_ISGID) {
175 if (mode & S_IXUSR) result += 's'; else result += 'S';
176 } else
177 if (mode & S_IXUSR) result += 'x'; else result += '-';
178
179 if (mode & S_IRGRP) result += 'r'; else result += '-';
180 if (mode & S_IWGRP) result += 'w'; else result += '-';
181
182 if (mode & S_ISGID) {
183 if (mode & S_IXGRP) result += 's'; else result += 'S';
184 } else
185 if (mode & S_IXGRP) result += 'x'; else result += '-';
186
187 if (mode & S_IROTH) result += 'r'; else result += '-';
188 if (mode & S_IWOTH) result += 'w'; else result += '-';
189
190 if (mode & S_ISVTX) {
191 if (mode & S_IXOTH) result += 't'; else result += 'T';
192 } else
193 if (mode & S_IXOTH) result += 'x'; else result += '-';
194
195 switch(mode & S_IFMT) {
196 case S_IFDIR: result += " directory"; break;
197 case S_IFCHR: result += " character special file "; break;
198 case S_IFBLK: result += " block special file"; break;
199 case S_IFREG: result += " regular file"; break;
200 case S_IFIFO: result += " FIFO special file"; break;
201 case S_IFLNK: result += " symbolic link"; break;
202 case S_IFSOCK: result += " socket"; break;
203 default: result += " UNKNOWN"; break;
204 }
205 return result;
206 }
207
208 uint32_t crc32(const uint8_t* data, size_t size, uint32_t crc) {
209 static constexpr uint32_t crcTable[256] = {
210 0x00000000, 0xedb88320, 0x36c98560, 0xdb710640, 0x6d930ac0, 0x802b89e0, 0x5b5a8fa0, 0xb6e20c80,
211 0xdb261580, 0x369e96a0, 0xedef90e0, 0x005713c0, 0xb6b51f40, 0x5b0d9c60, 0x807c9a20, 0x6dc41900,
212 0x5bf4a820, 0xb64c2b00, 0x6d3d2d40, 0x8085ae60, 0x3667a2e0, 0xdbdf21c0, 0x00ae2780, 0xed16a4a0,
213 0x80d2bda0, 0x6d6a3e80, 0xb61b38c0, 0x5ba3bbe0, 0xed41b760, 0x00f93440, 0xdb883200, 0x3630b120,
214 0xb7e95040, 0x5a51d360, 0x8120d520, 0x6c985600, 0xda7a5a80, 0x37c2d9a0, 0xecb3dfe0, 0x010b5cc0,
215 0x6ccf45c0, 0x8177c6e0, 0x5a06c0a0, 0xb7be4380, 0x015c4f00, 0xece4cc20, 0x3795ca60, 0xda2d4940,
216 0xec1df860, 0x01a57b40, 0xdad47d00, 0x376cfe20, 0x818ef2a0, 0x6c367180, 0xb74777c0, 0x5afff4e0,
217 0x373bede0, 0xda836ec0, 0x01f26880, 0xec4aeba0, 0x5aa8e720, 0xb7106400, 0x6c616240, 0x81d9e160,
218 0x826a23a0, 0x6fd2a080, 0xb4a3a6c0, 0x591b25e0, 0xeff92960, 0x0241aa40, 0xd930ac00, 0x34882f20,
219 0x594c3620, 0xb4f4b500, 0x6f85b340, 0x823d3060, 0x34df3ce0, 0xd967bfc0, 0x0216b980, 0xefae3aa0,
220 0xd99e8b80, 0x342608a0, 0xef570ee0, 0x02ef8dc0, 0xb40d8140, 0x59b50260, 0x82c40420, 0x6f7c8700,
221 0x02b89e00, 0xef001d20, 0x34711b60, 0xd9c99840, 0x6f2b94c0, 0x829317e0, 0x59e211a0, 0xb45a9280,
222 0x358373e0, 0xd83bf0c0, 0x034af680, 0xeef275a0, 0x58107920, 0xb5a8fa00, 0x6ed9fc40, 0x83617f60,
223 0xeea56660, 0x031de540, 0xd86ce300, 0x35d46020, 0x83366ca0, 0x6e8eef80, 0xb5ffe9c0, 0x58476ae0,
224 0x6e77dbc0, 0x83cf58e0, 0x58be5ea0, 0xb506dd80, 0x03e4d100, 0xee5c5220, 0x352d5460, 0xd895d740,
225 0xb551ce40, 0x58e94d60, 0x83984b20, 0x6e20c800, 0xd8c2c480, 0x357a47a0, 0xee0b41e0, 0x03b3c2c0,
226 0xe96cc460, 0x04d44740, 0xdfa54100, 0x321dc220, 0x84ffcea0, 0x69474d80, 0xb2364bc0, 0x5f8ec8e0,
227 0x324ad1e0, 0xdff252c0, 0x04835480, 0xe93bd7a0, 0x5fd9db20, 0xb2615800, 0x69105e40, 0x84a8dd60,
228 0xb2986c40, 0x5f20ef60, 0x8451e920, 0x69e96a00, 0xdf0b6680, 0x32b3e5a0, 0xe9c2e3e0, 0x047a60c0,
229 0x69be79c0, 0x8406fae0, 0x5f77fca0, 0xb2cf7f80, 0x042d7300, 0xe995f020, 0x32e4f660, 0xdf5c7540,
230 0x5e859420, 0xb33d1700, 0x684c1140, 0x85f49260, 0x33169ee0, 0xdeae1dc0, 0x05df1b80, 0xe86798a0,
231 0x85a381a0, 0x681b0280, 0xb36a04c0, 0x5ed287e0, 0xe8308b60, 0x05880840, 0xdef90e00, 0x33418d20,
232 0x05713c00, 0xe8c9bf20, 0x33b8b960, 0xde003a40, 0x68e236c0, 0x855ab5e0, 0x5e2bb3a0, 0xb3933080,
233 0xde572980, 0x33efaaa0, 0xe89eace0, 0x05262fc0, 0xb3c42340, 0x5e7ca060, 0x850da620, 0x68b52500,
234 0x6b06e7c0, 0x86be64e0, 0x5dcf62a0, 0xb077e180, 0x0695ed00, 0xeb2d6e20, 0x305c6860, 0xdde4eb40,
235 0xb020f240, 0x5d987160, 0x86e97720, 0x6b51f400, 0xddb3f880, 0x300b7ba0, 0xeb7a7de0, 0x06c2fec0,
236 0x30f24fe0, 0xdd4accc0, 0x063bca80, 0xeb8349a0, 0x5d614520, 0xb0d9c600, 0x6ba8c040, 0x86104360,
237 0xebd45a60, 0x066cd940, 0xdd1ddf00, 0x30a55c20, 0x864750a0, 0x6bffd380, 0xb08ed5c0, 0x5d3656e0,
238 0xdcefb780, 0x315734a0, 0xea2632e0, 0x079eb1c0, 0xb17cbd40, 0x5cc43e60, 0x87b53820, 0x6a0dbb00,
239 0x07c9a200, 0xea712120, 0x31002760, 0xdcb8a440, 0x6a5aa8c0, 0x87e22be0, 0x5c932da0, 0xb12bae80,
240 0x871b1fa0, 0x6aa39c80, 0xb1d29ac0, 0x5c6a19e0, 0xea881560, 0x07309640, 0xdc419000, 0x31f91320,
241 0x5c3d0a20, 0xb1858900, 0x6af48f40, 0x874c0c60, 0x31ae00e0, 0xdc1683c0, 0x07678580, 0xeadf06a0,
242 };
243
244 for (size_t i = 0; i < size; ++i) {
245 const uint32_t lookupIndex = (crc ^ data[i]) & 0xff;
246 crc = (crc >> 8) ^ crcTable[lookupIndex];
247 }
248
249 if (!size) {
250 // Finalize the CRC-32 value by inverting all the bits
251 crc ^= 0xFFFFFFFFu;
252 }
253 return crc;
254 }
255
256 static bool print_header = false;
257 static bool normalize_inodes = false;
258 static bool normalize_header = false;
259 static bool zero_symlink_padding = false;
260 static bool zero_directory_padding = false;
261 static bool zero_ea_padding = false;
262 static std::unordered_map<dump_ino_t, std::string> inode_map;
263
264 std::string ino_to_string(dump_ino_t ino) {
265 if (inode_map.contains(ino))
266 return inode_map[ino];
267 else
268 return std::to_string(ino);
269 }
270
271 void print_tape(uint8_t* data, size_t bytes, bswap_context* ctx) {
272 static bool inode_is_ea = false;
273 static bool inode_is_symlink = false;
274 static std::string indent = "";
275 static size_t blockno = 1;
276 static uint32_t crc;
277
278 if(!data || !bytes) {
279 if(ctx->seen_end) {
280 ctx->subcount = 0;
281 ctx->state = 0;
282 ctx->count = 0;
283 ctx->inode_is_directory = false;
284 ctx->inode_data_size = 0;
285 indent = "";
286 blockno = 1;
287 if (normalize_inodes) {
288 inode_map.clear();
289 inode_map[ROOTINO] = "/";
290 }
291 } else
292 ctx->new_vol = true;
293 return;
294 }
295 if (bytes % sizeof(header) == 4) {
296 bytes -= 4;
297 data += 4;
298 }
299 header* hdr = reinterpret_cast<header*>(data);
300 bytes /= sizeof *hdr;
301
302 auto skip_holes = [&ctx]() {
303 static size_t data_indexes = 0;
304 static size_t data_blocks = 0;
305 size_t holes_skipped = 0;
306 size_t indexes = 0;
307 while (ctx->count && !(*ctx->s_addr_ptr&1)) {
308 holes_skipped += get_s_addr_length(ctx->s_addr_ptr);
309 size_t hole_size = get_s_addr_length(ctx->s_addr_ptr) * 1024;
310 if (hole_size > ctx->inode_data_size)
311 hole_size = ctx->inode_data_size;
312 ctx->inode_data_size -= hole_size;
313 indexes++;
314 if(get_s_addr_length(ctx->s_addr_ptr) > 64)
315 ctx->s_addr_ptr += 2;
316 else
317 ctx->s_addr_ptr++;
318 ctx->count--;
319 }
320 if (!ctx->count) {
321 if (data_blocks) {
322 crc = crc32(nullptr, 0, crc);
323 std::cout << indent << " Processed " << data_blocks << " data blocks in " << data_indexes << " indexes" << " crc=" << std::hex << crc << std::dec << std::endl;
324 }
325 ctx->subcount = 0;
326 ctx->state = 0;
327 data_indexes = 0;
328 data_blocks = 0;
329 } else {
330 ctx->subcount = get_s_addr_length(ctx->s_addr_ptr);
331 data_blocks += ctx->subcount;
332 data_indexes++;
333 }
334 if (holes_skipped)
335 std::cout << indent << "Skipped " << holes_skipped << " holes in " << indexes << " indexes" << std::endl;
336 };
337 #define EXT2_XATTR_MAGIC 0xEA020000 // block EA
338 #define EXT2_XATTR_MAGIC2 0xEA020001 // in inode EA
339
340 auto print_ea = [&]() {
341 static std::vector<uint8_t> eabuffer;
342 if (ctx->count) {
343 if (!eabuffer.size()) {
344 /* h_checksum includes the blocknum in the
345 * calculation so it's useless in the dump and
346 * causes dumps to be different just based on
347 * the block that the EAs were stored in on the
348 * disk */
349 ext2_ext_attr_header* header = reinterpret_cast<ext2_ext_attr_header*>(hdr);
350 if (tohost(header->h_magic) == EXT2_EXT_ATTR_MAGIC && normalize_header) {
351 header->h_blocks = 0; // h_blocks and h_hash appear to not be set when using fuse
352 header->h_hash = 0;
353 header->h_checksum = 0;
354 }
355 }
356 eabuffer.insert(eabuffer.end(), reinterpret_cast<uint8_t*>(hdr), reinterpret_cast<uint8_t*>(hdr)+sizeof *hdr);
357 return;
358 }
359 const uint8_t* data_start;
360 const ext2_ext_attr_entry* entry;
361 const ext2_ext_attr_header* header = reinterpret_cast<const ext2_ext_attr_header*>(eabuffer.data());
362 switch(tohost(header->h_magic)) {
363 case EXT2_EXT_ATTR_MAGIC:
364 data_start = reinterpret_cast<const uint8_t*>(header);
365 entry = reinterpret_cast<const ext2_ext_attr_entry*>(header+1);
366 break;
367 case EXT2_EXT_ATTR_MAGIC+1:
368 data_start = reinterpret_cast<const uint8_t*>(header) + sizeof header->h_magic;
369 entry = reinterpret_cast<const ext2_ext_attr_entry*>(data_start);
370 break;
371 default:
372 errx(1, "Unknown magic %x in print_ea", header->h_magic);
373 }
374 while(tohost(entry->e_name_len) || tohost(entry->e_name_index) || tohost(entry->e_value_offs)) {
375 std::cout << "entry->e_name_len=" << (int)tohost(entry->e_name_len) << " entry->e_name_index=" << (int)tohost(entry->e_name_index) << " entry->e_value_offs=" << tohost(entry->e_value_offs) << std::endl;
376 std::string_view nametxt{ reinterpret_cast<const char*>(entry)+sizeof *entry, tohost(entry->e_name_len)};
377 std::string name;
378 switch (tohost(entry->e_name_index)) {
379 case 10:
380 name = std::string("gnu.") + std::string(nametxt);
381 break;
382 case 3:
383 name = std::string("system.posix_acl_default.") + std::string(nametxt);
384 break;
385 case 2:
386 name = std::string("system.posix_acl_access.") + std::string(nametxt);
387 break;
388 case 8:
389 name = std::string("system.richacl.") + std::string(nametxt);
390 break;
391 case 6:
392 name = std::string("security.") + std::string(nametxt);
393 break;
394 case 4:
395 name = std::string("trusted.") + std::string(nametxt);
396 break;
397 case 7:
398 name = std::string("system.") + std::string(nametxt);
399 break;
400 case 1:
401 name = std::string("user.") + std::string(nametxt);
402 break;
403 default:
404 errx(1, "unknown attribute");
405 }
406 std::vector<uint8_t> value;
407 value.insert(value.end(), data_start + tohost(entry->e_value_offs), data_start + tohost(entry->e_value_offs) + tohost(entry->e_value_size));
408 std::cout << indent << " EA: " << name << " value size is " << value.size() << std::endl;
409
410 size_t size = ((sizeof *entry + tohost(entry->e_name_len) + EXT2_EXT_ATTR_PAD - 1) / EXT2_EXT_ATTR_PAD) * EXT2_EXT_ATTR_PAD;
411 entry = reinterpret_cast<const ext2_ext_attr_entry*>(reinterpret_cast<const uint8_t*>(entry) + size);
412 }
413 eabuffer.clear();
414 };
415
416 auto print_direct = [&]() {
417 uint8_t* data = reinterpret_cast<uint8_t*>(hdr);
418 size_t consumed = 0;
419 direct* ptr = reinterpret_cast<direct*>(data);
420
421 auto strtype = [](uint8_t type) -> std::string {
422 switch((uint32_t)type << 12) {
423 case S_IFDIR: return "directory"; break;
424 case S_IFCHR: return "character special file "; break;
425 case S_IFBLK: return "block special file"; break;
426 case S_IFREG: return "regular file"; break;
427 case S_IFIFO: return "FIFO special file"; break;
428 case S_IFLNK: return "symbolic link"; break;
429 case S_IFSOCK: return "socket"; break;
430 case 0: return "UNKNOWN:0"; break;
431 // Versions 0.4b30 and 0.4b31 had a bug where this wasn't initialized.
432 default: return "UNKNOWN" + std::to_string(type); break;
433 }
434 };
435 while(consumed < sizeof *hdr && ctx->inode_data_size) {
436 uint8_t type = ptr->d_type;
437 uint8_t namlen = ptr->d_namlen;
438 uint16_t reclen = ptr->d_reclen;
439 if (zero_directory_padding && sizeof(direct) + namlen < reclen) {
440 memset(data+sizeof(direct)+namlen, 0, reclen-sizeof(direct)-namlen);
441 }
442 if (normalize_inodes) {
443 if (!inode_map.contains(ptr->d_ino)) {
444 if (std::string(".") == ptr->d_name || std::string("..") == ptr->d_name)
445 inode_map[ptr->d_ino] = "UNKNOWN(" + std::to_string(ptr->d_ino) + ")/";
446 else if (inode_map.contains(ctx->inode_num))
447 inode_map[ptr->d_ino] = inode_map[ctx->inode_num] + ptr->d_name + (((uint32_t)type << 12)==S_IFDIR?"/":"");
448 else // should never get here?
449 inode_map[ptr->d_ino] = "UNKNOWN(" + std::to_string(ctx->inode_num) + ")/" + ptr->d_name + (((uint32_t)type << 12)==S_IFDIR?"/":"");
450 }
451 }
452 std::cout << indent << " ino=" << ino_to_string(ptr->d_ino) << " reclen=" << ptr->d_reclen << " type=" << strtype(type) << " namlen=" << (int)namlen << " : " << ptr->d_name << std::endl;
453 if (normalize_inodes)
454 ptr->d_ino = 0;
455 #if BYTE_ORDER == BIG_ENDIAN
456 swap4(1, data); // ino
457 swap2(1, data); // reclen
458 if (ctx->oldinofmt) {
459 swap2(1, data); // namelen (was short prior to d_type being added
460 data -= 2;
461 }
462 data -= 6;
463 #endif
464 data += reclen;
465 consumed += reclen;
466 ctx->inode_data_size -= reclen;
467 ptr = reinterpret_cast<direct*>(data);
468 }
469 };
470
471 auto process_block = [&]() {
472 switch(ctx->state) {
473 case 0: {
474 indent = "";
475 if (hdr->c_magic != NFS_MAGIC || !checksum(hdr)) {
476 std::cout << "SKIPPING UNKNOWN at blockno " << blockno << " hdr->c_magic=" << hdr->c_magic << "NFS_MAGIC=" << NFS_MAGIC << " csum=" << checksum(hdr) << std::endl;
477 hdr++;
478 blockno++;
479 bytes--;
480 ctx->subcount = 0;
481 ctx->count = 0;
482 ctx->inode_is_directory = false;
483 ctx->inode_data_size = 0;
484 break;
485 }
486 header normhdr{*hdr};
487 if (normalize_header) {
488 normhdr.c_date = 0;
489 normhdr.c_ddate = 0;
490 normhdr.c_checksum = 0;
491 memset(normhdr.c_filesys, 0, sizeof normhdr.c_filesys);
492 memset(normhdr.c_dev, 0, sizeof normhdr.c_dev);
493 memset(normhdr.c_host, 0, sizeof normhdr.c_host);
494 normhdr.c_dinode.di_atime.tv_sec = 0;
495 normhdr.c_dinode.di_atime.tv_usec = 0;
496 normhdr.c_dinode.di_mtime.tv_sec = 0;
497 normhdr.c_dinode.di_mtime.tv_usec = 0;
498 normhdr.c_dinode.di_ctime.tv_sec = 0;
499 normhdr.c_dinode.di_ctime.tv_usec = 0;
500 normhdr.c_dinode.di_gen = 0;
501 if ((normhdr.c_dinode.di_mode & S_IFMT) != S_IFBLK && (normhdr.c_dinode.di_mode & S_IFMT) != S_IFCHR && !(normhdr.c_dinode.di_flags & EXT4_INLINE_DATA_FL)) {
502 memset(normhdr.c_dinode.di_db, 0, sizeof normhdr.c_dinode.di_db);
503 memset(normhdr.c_dinode.di_ib, 0, sizeof normhdr.c_dinode.di_ib);
504 }
505 }
506 if (normalize_inodes) {
507 normhdr.c_inumber = 0;
508 if (hdr->c_type == TS_END || hdr->c_type == TS_TAPE)
509 memset(normhdr.c_data.s_inos, 0, sizeof normhdr.c_data.s_inos);
510 }
511 header crchdr{normhdr};
512 #if BYTE_ORDER == BIG_ENDIAN
513 do_bswap_hdr(&crchdr);
514 #endif
515 if (print_header) {
516 fprintf(stderr, "c_type = %d\n", normhdr.c_type);
517 fprintf(stderr, "c_date = %d\n", normhdr.c_date);
518 fprintf(stderr, "c_ddate = %d\n", normhdr.c_ddate);
519 fprintf(stderr, "c_volume = %d\n", normhdr.c_volume);
520 fprintf(stderr, "c_tapea_lo = %d\n", normhdr.c_tapea_lo);
521 fprintf(stderr, "c_inumber = %d\n", normhdr.c_inumber);
522 fprintf(stderr, "c_magic = %d\n", normhdr.c_magic);
523 fprintf(stderr, "c_checksum = %d\n", normhdr.c_checksum);
524
525 //fprintf(stderr, "c_dinode = %d\n", normhdr.c_dinode);
526 crc = 0xffffffff;
527 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_dinode), sizeof crchdr.c_dinode, crc);
528 std::cout << indent << "c_dinode crc=" << std::hex << crc << std::dec << std::endl;
529 fprintf(stderr, "c_dinode.di_mode = %d\n", normhdr.c_dinode.di_mode);
530 fprintf(stderr, "c_dinode.di_nlink = %d\n", normhdr.c_dinode.di_nlink);
531 fprintf(stderr, "c_dinode.di_u.inumber = %d\n", normhdr.c_dinode.di_u.inumber);
532 fprintf(stderr, "c_dinode.di_size = %" PRIu64 "\n", normhdr.c_dinode.di_size);
533 fprintf(stderr, "c_dinode.di_atime = %d\n", *(uint32_t*)&normhdr.c_dinode.di_atime);
534 fprintf(stderr, "c_dinode.di_mtime = %d\n", *(uint32_t*)&normhdr.c_dinode.di_mtime);
535 fprintf(stderr, "c_dinode.di_ctime = %d\n", *(uint32_t*)&normhdr.c_dinode.di_ctime);
536 //fprintf(stderr, "c_dinode.di_db[NDADDR] = %d\n", normhdr.c_dinode.di_db[NDADDR]);
537 //fprintf(stderr, "c_dinode.di_ib[NIADDR] = %d\n", normhdr.c_dinode.di_ib[NIADDR]);
538 crc = 0xffffffff;
539 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_dinode.di_db), sizeof crchdr.c_dinode.di_db, crc);
540 std::cout << indent << "c_dinode.di_db crc=" << std::hex << crc << std::dec << std::endl;
541 crc = 0xffffffff;
542 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_dinode.di_ib), sizeof crchdr.c_dinode.di_ib, crc);
543 std::cout << indent << "c_dinode.di_ib crc=" << std::hex << crc << std::dec << std::endl;
544 fprintf(stderr, "c_dinode.di_flags = %d\n", normhdr.c_dinode.di_flags);
545 fprintf(stderr, "c_dinode.di_blocks = %d\n", normhdr.c_dinode.di_blocks);
546 fprintf(stderr, "c_dinode.di_gen = %d\n", normhdr.c_dinode.di_gen);
547 fprintf(stderr, "c_dinode.di_uid = %d\n", normhdr.c_dinode.di_uid);
548 fprintf(stderr, "c_dinode.di_gid = %d\n", normhdr.c_dinode.di_gid);
549 //fprintf(stderr, "c_dinode.di_spare[2] = %d\n", normhdr.c_dinode.di_spare[2]);
550 crc = 0xffffffff;
551 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_dinode.di_spare), sizeof crchdr.c_dinode.di_spare, crc);
552 std::cout << indent << "c_dinode.spare crc=" << std::hex << crc << std::dec << std::endl;
553
554 fprintf(stderr, "c_count = %d\n", normhdr.c_count);
555 //fprintf(stderr, "c_data = %d\n", normhdr.c_data);
556 crc = 0xffffffff;
557 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_data), sizeof crchdr.c_data, crc);
558 std::cout << indent << "c_data crc=" << std::hex << crc << std::dec << std::endl;
559 fprintf(stderr, "c_label[LBLSIZE] = %*.*s\n", LBLSIZE, LBLSIZE, normhdr.c_label);
560 fprintf(stderr, "c_level = %d\n", normhdr.c_level);
561 fprintf(stderr, "c_filesys[NAMELEN] = %*.*s\n", NAMELEN, NAMELEN, normhdr.c_filesys);
562 fprintf(stderr, "c_dev[NAMELEN] = %*.*s\n", NAMELEN, NAMELEN, normhdr.c_dev);
563 fprintf(stderr, "c_host[NAMELEN] = %*.*s\n", NAMELEN, NAMELEN, normhdr.c_host);
564 fprintf(stderr, "c_flags = %d\n", normhdr.c_flags);
565 fprintf(stderr, "c_firstrec_lo = %d\n", normhdr.c_firstrec_lo);
566 fprintf(stderr, "c_ntrec = %d\n", normhdr.c_ntrec);
567 fprintf(stderr, "c_extattributes = %d\n", normhdr.c_extattributes);
568 fprintf(stderr, "c_tapea_hi = %d\n", normhdr.c_tapea_hi);
569 fprintf(stderr, "c_firstrec_hi = %d\n", normhdr.c_firstrec_hi);
570 //fprintf(stderr, "c_spare[28] = %d\n", normhdr.c_spare);
571 crc = 0xffffffff;
572 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr.c_spare), sizeof crchdr.c_spare, crc);
573 std::cout << indent << "c_spare crc=" << std::hex << crc << std::dec << std::endl;
574
575 }
576 crc = 0xffffffff;
577 #if BYTE_ORDER == BIG_ENDIAN
578 if (hdr->c_type == TS_END || hdr->c_type == TS_TAPE) {
579 uint8_t* data = reinterpret_cast<uint8_t*>(crchdr.c_data.s_inos);
580 swap4(128, data);
581 }
582 #endif
583 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr), sizeof crchdr, crc);
584 std::cout << indent << convert_type(hdr->c_type) << " at blockno " << blockno << " inode=" << ino_to_string(hdr->c_inumber) << " mode=" << getmode(hdr->c_dinode.di_mode) << " size=" << hdr->c_dinode.di_size << " flags=" << convert_flags(hdr->c_flags) << " crc=" << std::hex << crc << std::dec << std::endl;
585 crc = 0xffffffff;
586 indent = " ";
587 ctx->seen_end = false;
588 switch (hdr->c_type) {
589 case TS_END:
590 ctx->seen_end = true;
591 [[fallthrough]];
592 case TS_TAPE: {
593 if (hdr->c_data.s_inos[1] == ROOTINO)
594 for (int i=1; i<128; i++)
595 if (hdr->c_data.s_inos[i])
596 std::cout << indent << "volinfo[" << i << "] = " << ino_to_string(hdr->c_data.s_inos[i]) << std::endl;
597 break;
598 }
599 case TS_CLRI:
600 ctx->count = hdr->c_count;
601 ctx->state = ctx->count?TS_CLRI:0;
602 std::cout << indent << ctx->count << " data blocks with CLR-inode bitmap ";
603 break;
604 case TS_BITS:
605 ctx->count = hdr->c_count;
606 ctx->state = ctx->count?TS_BITS:0;
607 std::cout << indent << ctx->count << " data blocks with HAS-inode bitmap ";
608 break;
609 case TS_INODE:
610 std::cout << indent << "INODE " << ino_to_string(hdr->c_inumber) << " mode=" << getmode(hdr->c_dinode.di_mode) << " size=" << hdr->c_dinode.di_size << " flags=" << convert_flags(hdr->c_flags) << std::endl;
611 inode_is_ea = hdr->c_flags & DR_EXTATTRIBUTES;
612 ctx->inode_is_directory = !inode_is_ea && (hdr->c_dinode.di_mode & S_IFMT) == S_IFDIR;
613 inode_is_symlink = !inode_is_ea && (hdr->c_dinode.di_mode & S_IFMT) == S_IFLNK;
614 ctx->inode_data_size = hdr->c_dinode.di_size;
615 ctx->inode_num = hdr->c_inumber;
616 [[fallthrough]];
617 case TS_ADDR:
618 ctx->count = hdr->c_count;
619 static_assert(sizeof ctx->s_addr == sizeof hdr->c_data.s_addrs);
620 std::memcpy(ctx->s_addr, hdr->c_data.s_addrs, sizeof ctx->s_addr);
621
622 #if 0
623 if (inode_is_ea) {
624 for(size_t i = 0; i<ctx->count; ++i) {
625 if(ctx->s_addr[i] >= 2)
626 break; /* must be 0.4b49 or later */
627 else if(ctx->s_addr[i] == 0) {
628 std::cerr << "Fixing up invalid c_addr record for xattrs (v0.4b40-0.4b42 bug)\n";
629 for(size_t i = 0; i<ctx->count; ++i)
630 ctx->s_addr[i] = 1;
631 break;
632 }
633 }
634 }
635 #endif
636 ctx->s_addr_ptr = ctx->s_addr;
637 skip_holes();
638 if (ctx->count)
639 ctx->state = TS_INODE;
640 break;
641 default:
642 errx(1, "unknown state on tape");
643 break;
644 }
645 if (normalize_inodes)
646 hdr->c_inumber = 0;
647 hdr++;
648 blockno++;
649 bytes--;
650 break;
651 }
652 case TS_INODE: {
653 if (ctx->inode_data_size < sizeof *hdr) {
654 if ((zero_symlink_padding && inode_is_symlink) ||
655 (zero_directory_padding && ctx->inode_is_directory) ||
656 (zero_ea_padding && inode_is_ea)) {
657 memset(reinterpret_cast<uint8_t*>(hdr)+ctx->inode_data_size, 0, sizeof *hdr - ctx->inode_data_size);
658 }
659 }
660
661 if (ctx->inode_is_directory)
662 print_direct();
663 else if (inode_is_ea)
664 print_ea();
665 header crchdr{*hdr};
666 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr), sizeof crchdr, crc);
667 hdr++;
668 blockno++;
669 bytes--;
670 if(--ctx->subcount == 0) {
671 if(--ctx->count == 0) {
672 ctx->state = 0;
673 if (inode_is_ea)
674 print_ea();
675 } else {
676 if(get_s_addr_length(ctx->s_addr_ptr) > 64)
677 ctx->s_addr_ptr += 2;
678 else
679 ctx->s_addr_ptr++;
680 }
681 skip_holes();
682 }
683 break;
684 }
685 case TS_BITS:
686 case TS_CLRI: {
687 header crchdr{*hdr};
688 if (normalize_inodes)
689 memset(&crchdr, 0, sizeof crchdr);
690 crc = crc32(reinterpret_cast<const uint8_t*>(&crchdr), sizeof crchdr, crc);
691 hdr++;
692 blockno++;
693 bytes--;
694 if(--ctx->count == 0) {
695 ctx->state = 0;
696 std::cout << "crc=" << std::hex << crc << std::dec << std::endl;
697 }
698 break;
699 }
700 default:
701 errx(1, "unexpected state while reading tape");
702 break;
703 }
704 };
705 if (ctx->new_vol) {
706 if (hdr->c_magic != NFS_MAGIC || !checksum(hdr) || hdr->c_type != TS_TAPE) {
707 std::cout << "EXPECTED TS_TAPE at start of volume hdr->c_magic=" << std::hex << hdr->c_magic << std::endl;
708 } else {
709 int saved_state = ctx->state;
710 ctx->state = 0;
711 process_block();
712 ctx->state = saved_state;
713 }
714 ctx->new_vol = false;
715 }
716 while (bytes)
717 process_block();
718 }
719
720 int main(int argc, char* argv[]) {
721
722 FakeTape tapein;
723 FILE* filein = nullptr;
724 const char* prog = argv[0];
725
726 const char* opts = "dehimnpsv";
727 struct option lopts[] = {
728 { .name = "debug", .has_arg = 0, .flag = nullptr, .val = 'd' },
729 { .name = "zero-ea-padding", .has_arg = 0, .flag = nullptr, .val = 'e' },
730 { .name = "normalize-inodes", .has_arg = 0, .flag = nullptr, .val = 'i' },
731 { .name = "print-header", .has_arg = 0, .flag = nullptr, .val = 'm' },
732 { .name = "normalize-header", .has_arg = 0, .flag = nullptr, .val = 'n' },
733 { .name = "zero-directory-padding", .has_arg = 0, .flag = nullptr, .val = 'p' },
734 { .name = "zero-symlink-padding", .has_arg = 0, .flag = nullptr, .val = 's' },
735 { .name = "version", .has_arg = 0, .flag = nullptr, .val = 'v' },
736 {},
737 };
738 std::string tapedev;
739
740 int ch;
741
742 while (( ch = getopt_long(argc, argv, opts, lopts, nullptr)) != -1)
743 switch(ch) {
744 case 'd':
745 tapein.debug = std::make_unique<std::ostream>(std::cerr.rdbuf());
746 tapein.debug->copyfmt(std::cerr);
747 tapein.debug->clear(std::cerr.rdstate());
748 break;
749 case 'e':
750 zero_ea_padding = true;
751 break;
752 case 'i':
753 normalize_inodes = true;
754 inode_map[ROOTINO] = "/";
755 break;
756 case 'm':
757 print_header = true;
758 break;
759 case 'n':
760 normalize_header = true;
761 break;
762 case 'p':
763 zero_directory_padding = true;
764 break;
765 case 's':
766 zero_symlink_padding = true;
767 break;
768 case 'v':
769 std::cerr << prog << " version " _DUMP_VERSION << std::endl;
770 return 0;
771 case 'h':
772 usage(prog, 0);
773 default:
774 usage(prog, 1);
775 }
776 argc -= optind;
777 argv += optind;
778
779 if (argc < 1)
780 usage(prog, 1);
781
782 bswap_context inctx;
783 bswap_context printctx;
784 inctx.to_host = true;
785
786 while(argc) {
787
788 warnx("Starting %s %s", prog, argv[0]);
789
790 /* Now open the dump image */
791 if(tapein.open(argv[0], O_RDONLY) != FakeTape::Response::OK)
792 if(!(filein = fopen(argv[0], "r")))
793 err(1, "%s cannot be opened.", argv[0]);
794
795 std::vector<uint8_t> buffer(FakeTape::getMaxBlockSize());
796
797 uint32_t ntrec = 0;
798 bool compressed = false;
799
800 auto rewind = [&tapein, &filein]() -> void {
801 if(filein) {
802 if (fseek(filein, -1024, SEEK_CUR) < 0)
803 err(1, "Failed to rewind dump image");
804 }
805 else if(tapein.bsr(1) != FakeTape::Response::OK)
806 err(1, "Failed to rewind tape image");
807 };
808
809 auto readData = [&tapein, &filein, &ntrec](std::vector<uint8_t>& buffer) -> size_t {
810 size_t readlen;
811 if(filein) {
812 size_t readsize = std::min(buffer.size(), (ntrec?ntrec:1)*(size_t)1024);
813 readlen = fread(buffer.data(), 1, readsize, filein);
814 }
815 else if(tapein.readData(buffer.data(), buffer.size(), &readlen) != FakeTape::Response::OK)
816 err(1, "Failed to read block from dump image");
817 return readlen;
818 };
819
820 auto readExtra = [&tapein, &filein](uint8_t* buffer) -> size_t {
821 size_t readlen;
822 if(filein) {
823 readlen = fread(buffer, 1, 4, filein);
824 }
825 else if(tapein.readData(buffer, 4, &readlen) != FakeTape::Response::OK)
826 err(1, "Failed to read continuation block from dump image");
827 return readlen;
828 };
829
830
831 if (lzo_init() != LZO_E_OK) {
832 fatal("internal error - lzo_init failed \n", prog);
833 }
834
835 do {
836 /* read the first 1K of bytes from the tape */
837 bswap_context tmp_inctx = inctx;
838 bswap_header(nullptr, 0, &tmp_inctx);
839 ntrec = 0;
840 /* Read the first block */
841 size_t readlen = readData(buffer);
842 if (readlen == 0)
843 break;
844 if (readlen < sizeof(header))
845 err(1, "Incomplete block read");
846
847 header* hdr = reinterpret_cast<header*>(buffer.data());
848
849 if (!checksum(hdr))
850 errx(1, "This doesn't appear to be a dump tape, or was written on a system with byteswapped values");
851
852 if (hdr->c_magic != NFS_MAGIC) {
853 tmp_inctx.to_cpu = true;
854 warnx("Input tape appears to be byteswapped");
855 }
856 bswap_header(buffer.data(), readlen, &tmp_inctx);
857
858 if (hdr->c_magic != NFS_MAGIC)
859 errx(1, "magic failure");
860
861 compressed = hdr->c_flags & DR_COMPRESSED;
862 ntrec = hdr->c_ntrec;
863
864 std::cout << "Tape has ntrec of " << ntrec << std::endl;
865 rewind();
866
867 /* Now start properly */
868 inctx.to_cpu = tmp_inctx.to_cpu;
869 bswap_header(nullptr, 0, &inctx);
870 print_tape(nullptr, 0, &printctx);
871 readlen = readData(buffer);
872 if((ntrec && readlen != ntrec*1024) || readlen%1024)
873 errx(1, "Bad blocksize read on first block %zu", readlen);
874
875 bswap_header(buffer.data(), readlen, &inctx);
876 print_tape(buffer.data(), readlen, &printctx);
877
878 std::optional<bool> demangle_bitfields;
879 while(true) {
880
881 readlen = readData(buffer);
882 if (readlen == 0)
883 break;
884 uint32_t bsize = readlen;
885 uint32_t ctype = 0;
886 uint32_t cflag = 0;
887
888 if (compressed) {
889 if (inctx.to_cpu) {
890 auto data = buffer.data();
891 swap4(1, data);
892 }
893 uint32_t clen = *reinterpret_cast<uint32_t*>(buffer.data());
894 if (!demangle_bitfields.has_value()) {
895 if(clen>>31)
896 // Case 2b. Only way mc can be set.
897 demangle_bitfields = true;
898 /* blocks written without compression must be exactly ntrec*TP_BSIZE in size */
899 else if ((clen & 0xfffffff) != ntrec * TP_BSIZE)
900 // This covers case 2a and 1a. 2a because length will be odd when read mangled, and 1a because length will be 16x too big.
901 demangle_bitfields = false;
902 else
903 // Only case 1b remains.
904 demangle_bitfields = true;
905 if (*demangle_bitfields)
906 std::cout << "Warning: Tape appears to have been written with different bitfield ordering" << std::endl;
907 }
908 if (*demangle_bitfields) {
909 bsize = clen & 0xfffffff;
910 ctype = (clen&0x70000000)>>28;
911 cflag = clen>>31;
912 } else {
913 bsize = clen >> 4;
914 ctype = (clen&0xe)>>1;
915 cflag = clen&1;
916 }
917 if (filein) {
918 if (bsize < readlen) {
919 fseek(filein, (off_t)bsize+4-(off_t)readlen, SEEK_CUR);
920 readlen = bsize + 4;
921 }
922 }
923 if (bsize == readlen) {
924 size_t extra = readExtra(buffer.data() + readlen);
925 readlen += extra;
926 } else if (bsize != readlen - 4) {
927 if (readlen == ntrec*1024) {
928 warnx("Assuming buggy 0.4b45 compressed dump. Ignoring compression flag");
929 compressed = 0;
930 std::memmove(buffer.data()+4, buffer.data(), readlen);
931 cflag = 0;
932 bsize = readlen;
933 } else
934 err(1, "Unexpected size of compressed block bsize=%d readlen=%zd clen=%x demangle=%d", bsize, readlen, clen, *demangle_bitfields);
935 }
936 if (cflag) {
937 switch(ctype) {
938 case COMPRESS_ZLIB: {
939 std::vector<uint8_t> cmprbuf(FakeTape::getMaxBlockSize());
940 std::swap(cmprbuf, buffer);
941 uLongf decmprlen = buffer.size();
942 int status = uncompress(buffer.data()+4, &decmprlen, cmprbuf.data()+4, bsize);
943 switch (status) {
944 case Z_OK: break;
945 case Z_MEM_ERROR: errx(1, "Memory error while decompressing");
946 case Z_BUF_ERROR: errx(1, "BUF error while decompressing");;
947 case Z_DATA_ERROR: errx(1, "Corrupt compressed data while decompressing");
948 default: errx(1, "Unexpected return from uncompress");
949 }
950 bsize = decmprlen;
951 break;
952 }
953 case COMPRESS_BZLIB: {
954 std::vector<uint8_t> cmprbuf(FakeTape::getMaxBlockSize());
955 std::swap(cmprbuf, buffer);
956 unsigned int decmprlen = buffer.size();
957 int status = BZ2_bzBuffToBuffDecompress((char*)buffer.data()+4, &decmprlen, (char*)cmprbuf.data()+4, bsize, 0, 0);
958
959 switch (status) {
960 case BZ_OK: break;
961 case BZ_MEM_ERROR: errx(1, "Memory error while decompressing");
962 case BZ_OUTBUFF_FULL: errx(1, "BUF error while decompressing");;
963 case BZ_DATA_ERROR:
964 case BZ_DATA_ERROR_MAGIC:
965 case BZ_UNEXPECTED_EOF:
966 errx(1, "Corrupt compressed data while decompressing");
967 default: errx(1, "Unexpected return from uncompress");
968 }
969 bsize = decmprlen;
970 break;
971 }
972 case COMPRESS_LZO: {
973 std::vector<uint8_t> cmprbuf(FakeTape::getMaxBlockSize());
974 std::swap(cmprbuf, buffer);
975 lzo_uint decmprlen = buffer.size();
976 int status = lzo1x_decompress(cmprbuf.data()+4, bsize, buffer.data()+4, &decmprlen, nullptr);
977
978 switch (status) {
979 case LZO_E_OK: break;
980 case LZO_E_ERROR: errx(1, "LZO error while decompressing");
981 case LZO_E_EOF_NOT_FOUND: errx(1, "LZO No EOF error while decompressing");;
982 default: errx(1, "Unexpected return from LZO uncompress");
983 }
984 bsize = decmprlen;
985 break;
986 }
987 }
988 }
989 bswap_header(buffer.data()+4, bsize, &inctx);
990 readlen = bsize + 4;
991 } else {
992 bswap_header(buffer.data(), readlen, &inctx);
993 std::memmove(buffer.data()+4, buffer.data(), readlen);
994 readlen += 4;
995 }
996 /* At this point we have uncompressed data with a compression header (header contains garbage) */
997 cflag = 0;
998 ctype = 0;
999 print_tape(buffer.data(), readlen, &printctx);
1000 }
1001 } while(true);
1002 argv++;
1003 argc--;
1004 }
1005
1006 warnx("Finished");
1007 }
1008
1009 /* vim: set sw=8 sts=8 ts=8 noexpandtab: */