wok-current diff fusecloop/stuff/fusecloop.u @ rev 10932
fusecloop: add old version support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Aug 26 17:50:10 2011 +0200 (2011-08-26) |
parents | |
children | 9de4fcf2f70c |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/fusecloop/stuff/fusecloop.u Fri Aug 26 17:50:10 2011 +0200 1.3 @@ -0,0 +1,160 @@ 1.4 +--- compressed_loop.h 1.5 ++++ compressed_loop.h 1.6 +@@ -41,6 +41,55 @@ 1.7 + /* data_index (num_blocks 64bit pointers, network order)... */ 1.8 + /* compressed data (gzip block compressed format)... */ 1.9 + 1.10 ++struct block_info 1.11 ++{ 1.12 ++ loff_t offset; /* 64-bit offsets of compressed block */ 1.13 ++ u_int32_t size; /* 32-bit compressed block size */ 1.14 ++ u_int32_t optidx; /* 32-bit index number */ 1.15 ++}; 1.16 ++ 1.17 ++static inline char *build_index(struct block_info *offsets, unsigned long n) 1.18 ++{ 1.19 ++ u_int32_t *ofs32 = (u_int32_t *) offsets; 1.20 ++ loff_t *ofs64 = (loff_t *) offsets; 1.21 ++ if (ofs32[0] == 0) { 1.22 ++ if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */ 1.23 ++ do { 1.24 ++ offsets[n].offset = __be64_to_cpu(offsets[n].offset); 1.25 ++ offsets[n].size = ntohl(offsets[n].size); 1.26 ++ } while (n--); 1.27 ++ return "128BE accelerated knoppix 1.0"; 1.28 ++ } 1.29 ++ else { /* V2.0 */ 1.30 ++ loff_t last = __be64_to_cpu(ofs64[n+1]); 1.31 ++ do { 1.32 ++ offsets[n].size = last - 1.33 ++ (offsets[n].offset = __be64_to_cpu(ofs64[n])); 1.34 ++ last = offsets[n].offset; 1.35 ++ } while (n--); 1.36 ++ return "64BE v2.0"; 1.37 ++ } 1.38 ++ } 1.39 ++ else if (ofs32[1] == 0) { /* V1.0 */ 1.40 ++ loff_t last = __be64_to_cpu(ofs64[n+1]); 1.41 ++ do { 1.42 ++ offsets[n].size = last - 1.43 ++ (offsets[n].offset = __le64_to_cpu(ofs64[n])); 1.44 ++ last = offsets[n].offset; 1.45 ++ } while (n--); 1.46 ++ return "64LE v1.0"; 1.47 ++ } 1.48 ++ else { /* V0.68 */ 1.49 ++ loff_t last = ntohl(ofs32[n+1]); 1.50 ++ do { 1.51 ++ offsets[n].size = last - 1.52 ++ (offsets[n].offset = ntohl(ofs32[n])); 1.53 ++ last = offsets[n].offset; 1.54 ++ } while (n--); 1.55 ++ return "32BE v0.68"; 1.56 ++ } 1.57 ++} 1.58 ++ 1.59 + /* Cloop suspend IOCTL */ 1.60 + #define CLOOP_SUSPEND 0x4C07 1.61 + 1.62 + 1.63 +--- cloopreader.h 1.64 ++++ cloopreader.h 1.65 +@@ -33,7 +33,7 @@ 1.66 + int numblocks; 1.67 + ulong blocksize; 1.68 + 1.69 +- loff_t* toc; /* Data index */ 1.70 ++ struct block_info *toc; /* Data index */ 1.71 + size_t tocsize; 1.72 + 1.73 + unsigned char* cblock; /* Compressed block */ 1.74 + 1.75 +--- cloopreader.c 1.76 ++++ cloopreader.c 1.77 +@@ -59,10 +59,11 @@ 1.78 + 1.79 + ALLOC(c->pblock,c->blocksize); 1.80 + 1.81 +- c->tocsize=sizeof *c->toc * (c->numblocks+1); /* One extra address is position of EOF */ 1.82 ++ c->tocsize=sizeof(*c->toc) * c->numblocks; 1.83 + ALLOC(c->toc,c->tocsize); 1.84 + 1.85 + OP(read_all(c->fh,c->toc,c->tocsize)); /* read Data Index */ 1.86 ++ build_index(c->toc, c->numblocks); 1.87 + c->cblocksizecur=0; 1.88 + c->curblock=-1; 1.89 + return 0; 1.90 +@@ -79,10 +80,10 @@ 1.91 + if(page>=c->numblocks){errno=EFAULT;return -1;} 1.92 + c->curblock=page; 1.93 + 1.94 +- bprintf("Seeking to 0x%Lx\n",btc(c->toc[page])); 1.95 +- OP(lseek(c->fh,btc(c->toc[page]), SEEK_SET)); 1.96 ++ bprintf("Seeking to 0x%Lx\n",c->toc[page].offset); 1.97 ++ OP(lseek(c->fh,c->toc[page].offset, SEEK_SET)); 1.98 + 1.99 +- c->cblocksize=btc(c->toc[page+1]) - btc(c->toc[page]); 1.100 ++ c->cblocksize=c->toc[page].size; 1.101 + bprintf("Compressed size=%lu\n",c->cblocksize); 1.102 + if(c->cblocksize > c->cblocksizecur){ 1.103 + if(c->cblocksizecur)free(c->cblock); 1.104 +--- extract_compressed_fs.c 1.105 ++++ extract_compressed_fs.c 1.106 +@@ -7,6 +7,7 @@ 1.107 + struct cloop_head head; 1.108 + unsigned int i; 1.109 + unsigned char *buffer, *clear_buffer; 1.110 ++ struct block_info *offsets; 1.111 + 1.112 + if (argc != 2) { 1.113 + fprintf(stderr, "Need filename\n"); 1.114 +@@ -30,35 +31,34 @@ 1.115 + fprintf(stderr, "%u blocks of size %u. Preamble:\n%s\n", 1.116 + ntohl(head.num_blocks), ntohl(head.block_size), head.preamble); 1.117 + 1.118 ++ i = ntohl(head.num_blocks) * sizeof(*offsets); 1.119 ++ offsets = malloc(i); 1.120 ++ if (!offsets || read(handle, offsets, i) != i) { 1.121 ++ perror("Reading index\n"); 1.122 ++ exit(1); 1.123 ++ } 1.124 ++ 1.125 ++ fprintf(stderr, "Index %s.\n", 1.126 ++ build_index(offsets, ntohl(head.num_blocks))); 1.127 ++ 1.128 + for (i = 0; i < ntohl(head.num_blocks); i++) { 1.129 +- int currpos; 1.130 + unsigned long destlen = ntohl(head.block_size); 1.131 +- loff_t offset[2]; 1.132 +- unsigned int size; 1.133 ++ unsigned int size = offsets[i].size; 1.134 + 1.135 +- read(handle, &offset, 2*sizeof(loff_t)); 1.136 +- lseek(handle, -sizeof(loff_t), SEEK_CUR); 1.137 +- 1.138 +- currpos = lseek(handle, 0, SEEK_CUR); 1.139 +- if (lseek(handle, __be64_to_cpu(offset[0]), SEEK_SET) < 0) { 1.140 ++ if (lseek(handle, offsets[i].offset, SEEK_SET) < 0) { 1.141 + fprintf(stderr, "lseek to %Lu: %s\n", 1.142 +- __be64_to_cpu(offset[0]), strerror(errno)); 1.143 ++ offsets[i].offset, strerror(errno)); 1.144 + exit(1); 1.145 + } 1.146 + 1.147 +- size=__be64_to_cpu(offset[1])-__be64_to_cpu(offset[0]); 1.148 + if (size > ntohl(head.block_size) + ntohl(head.block_size)/1000 1.149 + + 12 + 4) { 1.150 + fprintf(stderr, 1.151 + "Size %u for block %u (offset %Lu) too big\n", 1.152 +- size, i, __be64_to_cpu(offset[0])); 1.153 ++ size, i, offsets[i].offset); 1.154 + exit(1); 1.155 + } 1.156 + read(handle, buffer, size); 1.157 +- if (lseek(handle, currpos, SEEK_SET) < 0) { 1.158 +- perror("seeking"); 1.159 +- exit(1); 1.160 +- } 1.161 + 1.162 + fprintf(stderr, "Block %u length %u => %lu\n", 1.163 + i, size, destlen);