wok diff fusecloop/stuff/fusecloop.u @ rev 25705
fusecloop/extract_compressed_fs: can convert to v0.68 or v1.0
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 22 12:48:49 2024 +0000 (12 months ago) |
parents | 1523c0330556 |
children |
line diff
1.1 --- a/fusecloop/stuff/fusecloop.u Sat Dec 25 15:56:57 2021 +0000 1.2 +++ b/fusecloop/stuff/fusecloop.u Sat Jun 22 12:48:49 2024 +0000 1.3 @@ -2444,3 +2444,133 @@ 1.4 if (getenv("CLOOP_TABLE") != NULL) { 1.5 fprintf(stderr, "CLOOP_TABLE ascii: offset, size, flags\n"); 1.6 for (i = 0; i < num_blocks; i++) { 1.7 +=== convert to v0 and v1 1.8 +--- extract_compressed_fs.c 1.9 ++++ extract_compressed_fs.c 1.10 +@@ -1,7 +1,8 @@ 1.11 + /* Extracts a filesystem back from a compressed fs file */ 1.12 + #define _LARGEFILE64_SOURCE 1.13 + #include "common_header.h" 1.14 +-#define CLOOP_PREAMBLE "#!/bin/sh\n" "#V2.0 Format\n" "modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" "exit $?\n" 1.15 ++//#define CLOOP_PREAMBLE "#!/bin/sh\n" "#V2.0 Format\n" "modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" "exit $?\n" 1.16 ++#define CLOOP_PREAMBLE "modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" "exit $?\n" 1.17 + 1.18 + #include "cloopunpack.c" 1.19 + static char *packnames[CLOOP_COMPRESSOR_MAX+1] = { CLOOP_COMPRESSOR_NAMES }; 1.20 +@@ -72,7 +73,7 @@ 1.21 + { 1.22 + struct cloop_head head; 1.23 + unsigned int i, v4_header_last; 1.24 +- unsigned long n, len; 1.25 ++ unsigned long n, p, len; 1.26 + uLongf ulen; 1.27 + off64_t end; 1.28 + 1.29 +@@ -81,7 +82,8 @@ 1.30 + #ifdef CLOOP_DEBUG 1.31 + "[CLOOP_TAIL=1|CLOOP_ZINDEX=1|CLOOP_INDEX=1|CLOOP_TABLE=1] " 1.32 + #endif 1.33 +- "extract_compressed_fs file [--convert-to-v2] > output\n"); 1.34 ++// "extract_compressed_fs file [--convert-to-v2] > output\n"); 1.35 ++ "extract_compressed_fs file [--convert-to {0|1|2}] > output\n"); 1.36 + exit(1); 1.37 + } 1.38 + 1.39 +@@ -118,7 +120,7 @@ 1.40 + void *table; 1.41 + struct cloop_tail tail; 1.42 + unsigned long table_size; 1.43 +- 1.44 ++ 1.45 + end = lseek64(handle, 0, SEEK_END); 1.46 + if (lseek64(handle, end - sizeof(tail), SEEK_SET) < 0 || 1.47 + read(handle, &tail, sizeof(tail)) != sizeof(tail) || 1.48 +@@ -128,6 +130,15 @@ 1.49 + exit(1); 1.50 + } 1.51 + #ifdef CLOOP_DEBUG 1.52 ++struct cloop_tail 1.53 ++{ 1.54 ++ u_int32_t table_size; 1.55 ++ u_int32_t index_size; /* size:4 unused:3 ctrl-c:1 lastlen:24 */ 1.56 ++#define CLOOP3_INDEX_SIZE(x) ((unsigned int)((x) & 0xF)) 1.57 ++#define CLOOP3_TRUNCATED(x) ((unsigned int)((x) & 0x80) >> 7) 1.58 ++#define CLOOP3_LASTLEN(x) (unsigned int)((x) >> 8) 1.59 ++ u_int32_t num_blocks; 1.60 ++}; 1.61 + if (getenv("CLOOP_TAIL") != NULL) { 1.62 + fprintf(stderr, "Table size:32 %u, index_size:4 %u, unused:3\n", 1.63 + tail.table_size,CLOOP3_INDEX_SIZE(tail.index_size)); 1.64 +@@ -183,7 +194,7 @@ 1.65 + exit(1); 1.66 + } 1.67 + } 1.68 +- 1.69 ++ 1.70 + if (v4_header_last) { 1.71 + lseek64(handle, 0, SEEK_SET); 1.72 + } 1.73 +@@ -214,24 +225,55 @@ 1.74 + 1.75 + if (argc > 2) { 1.76 + loff_t data, ofs = ((num_blocks + 1) * sizeof(ofs)) + sizeof(head); 1.77 ++ unsigned long data32; 1.78 ++ int version = 2; 1.79 + 1.80 +- strcpy(head.preamble, CLOOP_PREAMBLE); 1.81 ++ memset(head.preamble, 0, sizeof(head.preamble)); 1.82 ++ strcpy(head.preamble, "#!/bin/sh\n"); 1.83 ++ if (argc > 3) { 1.84 ++ switch (*argv[3]) { 1.85 ++ case '0': 1.86 ++ version = 0; 1.87 ++ ofs = ((num_blocks + 1) * sizeof(data32)) + sizeof(head); 1.88 ++ break; 1.89 ++ case '1': 1.90 ++ version = 1; 1.91 ++ strcat(head.preamble, "#V1.0 Format\n"); 1.92 ++ } 1.93 ++ } 1.94 ++ if (version == 2) { 1.95 ++ strcat(head.preamble, "#V2.0 Format\n"); 1.96 ++ } 1.97 ++ strcat(head.preamble, CLOOP_PREAMBLE); 1.98 + write(STDOUT_FILENO, &head, n = sizeof(head)); 1.99 +- for (i = 0; i < num_blocks; i++) { 1.100 +- data = __be64_to_cpu(ofs); 1.101 +- write(STDOUT_FILENO, &data, sizeof(data)); 1.102 +- n += sizeof(data); 1.103 ++ for (i = 0; i <= num_blocks; i++) { 1.104 ++ p = n; 1.105 ++ switch (version) { 1.106 ++ case 0: 1.107 ++ data32 = __le32_to_cpu(ofs); 1.108 ++ n += sizeof(data32); 1.109 ++ write(STDOUT_FILENO, &data32, sizeof(data32)); 1.110 ++ break; 1.111 ++ case 1: 1.112 ++ data = __le64_to_cpu(ofs); 1.113 ++ n += sizeof(data); 1.114 ++ write(STDOUT_FILENO, &data, sizeof(data)); 1.115 ++ break; 1.116 ++ case 2: 1.117 ++ data = __be64_to_cpu(ofs); 1.118 ++ n += sizeof(data); 1.119 ++ write(STDOUT_FILENO, &data, sizeof(data)); 1.120 ++ } 1.121 + if (offsets[i].flags == CLOOP_COMPRESSOR_ZLIB) 1.122 + ofs += offsets[i].size; 1.123 + else 1.124 + ofs += get_block(i,argc); 1.125 + } 1.126 +- data = __be64_to_cpu(ofs); 1.127 +- write(STDOUT_FILENO, &data, sizeof(data)); 1.128 ++ n = p; 1.129 + } 1.130 + for (i = 0; i < num_blocks; i++) { 1.131 + 1.132 +- fprintf(stderr, "Block %u %s at %llu length %lu ", 1.133 ++ fprintf(stderr, "Block %u %s at %Lu length %u ", 1.134 + i, packnames[offsets[i].flags], offsets[i].offset, offsets[i].size); 1.135 + ulen = get_block(i, argc); 1.136 + fprintf(stderr, " => %lu\n", ulen);