wok-4.x rev 10933
fusecloop: add v3.0 support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Aug 26 20:39:15 2011 +0200 (2011-08-26) |
parents | ff0097ff50cd |
children | 27a1c1c0fdf3 |
files | fusecloop/stuff/fusecloop.u |
line diff
1.1 --- a/fusecloop/stuff/fusecloop.u Fri Aug 26 17:50:10 2011 +0200 1.2 +++ b/fusecloop/stuff/fusecloop.u Fri Aug 26 20:39:15 2011 +0200 1.3 @@ -1,9 +1,15 @@ 1.4 --- compressed_loop.h 1.5 +++ compressed_loop.h 1.6 -@@ -41,6 +41,55 @@ 1.7 +@@ -41,6 +41,85 @@ 1.8 /* data_index (num_blocks 64bit pointers, network order)... */ 1.9 /* compressed data (gzip block compressed format)... */ 1.10 1.11 ++struct cloop_tail 1.12 ++{ 1.13 ++ u_int32_t index_size; 1.14 ++ u_int32_t num_blocks; 1.15 ++}; 1.16 ++ 1.17 +struct block_info 1.18 +{ 1.19 + loff_t offset; /* 64-bit offsets of compressed block */ 1.20 @@ -11,46 +17,70 @@ 1.21 + u_int32_t optidx; /* 32-bit index number */ 1.22 +}; 1.23 + 1.24 -+static inline char *build_index(struct block_info *offsets, unsigned long n) 1.25 ++static inline char *build_index(struct block_info *offsets, unsigned long n, 1.26 ++ unsigned long block_size) 1.27 +{ 1.28 ++ u_int16_t *ofs16 = (u_int16_t *) offsets; 1.29 + u_int32_t *ofs32 = (u_int32_t *) offsets; 1.30 + loff_t *ofs64 = (loff_t *) offsets; 1.31 ++ 1.32 + if (ofs32[0] == 0) { 1.33 + if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */ 1.34 -+ do { 1.35 ++ while (n--) { 1.36 + offsets[n].offset = __be64_to_cpu(offsets[n].offset); 1.37 + offsets[n].size = ntohl(offsets[n].size); 1.38 -+ } while (n--); 1.39 ++ } 1.40 + return "128BE accelerated knoppix 1.0"; 1.41 + } 1.42 + else { /* V2.0 */ 1.43 -+ loff_t last = __be64_to_cpu(ofs64[n+1]); 1.44 -+ do { 1.45 ++ loff_t last = __be64_to_cpu(ofs64[n]); 1.46 ++ while (n--) { 1.47 + offsets[n].size = last - 1.48 + (offsets[n].offset = __be64_to_cpu(ofs64[n])); 1.49 + last = offsets[n].offset; 1.50 -+ } while (n--); 1.51 ++ } 1.52 + return "64BE v2.0"; 1.53 + } 1.54 + } 1.55 + else if (ofs32[1] == 0) { /* V1.0 */ 1.56 -+ loff_t last = __be64_to_cpu(ofs64[n+1]); 1.57 -+ do { 1.58 ++ loff_t last = __be64_to_cpu(ofs64[n]); 1.59 ++ while (n--) { 1.60 + offsets[n].size = last - 1.61 + (offsets[n].offset = __le64_to_cpu(ofs64[n])); 1.62 + last = offsets[n].offset; 1.63 -+ } while (n--); 1.64 ++ } 1.65 + return "64LE v1.0"; 1.66 + } 1.67 -+ else { /* V0.68 */ 1.68 -+ loff_t last = ntohl(ofs32[n+1]); 1.69 -+ do { 1.70 ++ else if (ntohl(ofs32[0]) == (4*n) + 0x8C) { /* V0.68 */ 1.71 ++ loff_t last = ntohl(ofs32[n]); 1.72 ++ while (n--) { 1.73 + offsets[n].size = last - 1.74 + (offsets[n].offset = ntohl(ofs32[n])); 1.75 + last = offsets[n].offset; 1.76 -+ } while (n--); 1.77 ++ } 1.78 + return "32BE v0.68"; 1.79 + } 1.80 ++ else { /* V3.0 */ 1.81 ++ char *type; 1.82 ++ int i, j, smallest; 1.83 ++ 1.84 ++ smallest = (block_size < 32768) ? 0 : block_size>>10; 1.85 ++ if (block_size > 0x10000) { 1.86 ++ for (i = 0; i < n; i++) 1.87 ++ offsets[n].size = smallest + ntohl(ofs32[n]); 1.88 ++ type = "32BE size v3.0"; 1.89 ++ } 1.90 ++ else { 1.91 ++ for (i = 0; i < n; i++) 1.92 ++ offsets[n].size = smallest + ntohs(ofs16[n]); 1.93 ++ type = "16BE size v3.0"; 1.94 ++ } 1.95 ++ for (i = j = 0; i < n; i++) { 1.96 ++ offsets[i].offset = j; 1.97 ++ j += offsets[i].size; 1.98 ++ } 1.99 ++ return type; 1.100 ++ } 1.101 +} 1.102 + 1.103 /* Cloop suspend IOCTL */ 1.104 @@ -71,20 +101,29 @@ 1.105 1.106 --- cloopreader.c 1.107 +++ cloopreader.c 1.108 -@@ -59,10 +59,11 @@ 1.109 +@@ -59,10 +59,20 @@ 1.110 1.111 ALLOC(c->pblock,c->blocksize); 1.112 1.113 - c->tocsize=sizeof *c->toc * (c->numblocks+1); /* One extra address is position of EOF */ 1.114 + c->tocsize=sizeof(*c->toc) * c->numblocks; 1.115 ++ if (c->numblocks == -1) { 1.116 ++ struct cloop_tail tail; 1.117 ++ 1.118 ++ OP(lseek(c->fh, - sizeof(tail), SEEK_END)); 1.119 ++ OP(read_all(c->fh, &tail, sizeof(tail))); 1.120 ++ c->numblocks = ntohl(tail.num_blocks); 1.121 ++ c->tocsize = ntohl(tail.index_size) * c->numblocks; 1.122 ++ OP(lseek(c->fh, - sizeof(tail) - c->tocsize, SEEK_END)); 1.123 ++ } 1.124 ALLOC(c->toc,c->tocsize); 1.125 1.126 OP(read_all(c->fh,c->toc,c->tocsize)); /* read Data Index */ 1.127 -+ build_index(c->toc, c->numblocks); 1.128 ++ build_index(c->toc, c->numblocks, c->blocksize); 1.129 c->cblocksizecur=0; 1.130 c->curblock=-1; 1.131 return 0; 1.132 -@@ -79,10 +80,10 @@ 1.133 +@@ -79,10 +89,10 @@ 1.134 if(page>=c->numblocks){errno=EFAULT;return -1;} 1.135 c->curblock=page; 1.136 1.137 @@ -98,6 +137,7 @@ 1.138 bprintf("Compressed size=%lu\n",c->cblocksize); 1.139 if(c->cblocksize > c->cblocksizecur){ 1.140 if(c->cblocksizecur)free(c->cblock); 1.141 + 1.142 --- extract_compressed_fs.c 1.143 +++ extract_compressed_fs.c 1.144 @@ -7,6 +7,7 @@ 1.145 @@ -108,19 +148,33 @@ 1.146 1.147 if (argc != 2) { 1.148 fprintf(stderr, "Need filename\n"); 1.149 -@@ -30,35 +31,34 @@ 1.150 +@@ -30,35 +31,48 @@ 1.151 fprintf(stderr, "%u blocks of size %u. Preamble:\n%s\n", 1.152 ntohl(head.num_blocks), ntohl(head.block_size), head.preamble); 1.153 1.154 -+ i = ntohl(head.num_blocks) * sizeof(*offsets); 1.155 ++ i = ntohl(head.num_blocks); 1.156 ++ if (i == -1) { 1.157 ++ struct cloop_tail tail; 1.158 ++ if (lseek(handle, - sizeof(tail), SEEK_END) < 0 || 1.159 ++ read(handle, &tail, sizeof(tail)) != sizeof(tail) || 1.160 ++ lseek(handle, - sizeof(tail) - 1.161 ++ (ntohl(tail.num_blocks) * ntohl(tail.index_size)), 1.162 ++ SEEK_END) < 0) { 1.163 ++ perror("Reading tail\n"); 1.164 ++ exit(1); 1.165 ++ } 1.166 ++ head.num_blocks = tail.num_blocks; 1.167 ++ i = ntohl(tail.num_blocks) * ntohl(tail.index_size); 1.168 ++ } 1.169 ++ else i *= sizeof(*offsets); 1.170 + offsets = malloc(i); 1.171 + if (!offsets || read(handle, offsets, i) != i) { 1.172 + perror("Reading index\n"); 1.173 + exit(1); 1.174 + } 1.175 + 1.176 -+ fprintf(stderr, "Index %s.\n", 1.177 -+ build_index(offsets, ntohl(head.num_blocks))); 1.178 ++ fprintf(stderr, "Index %s.\n", build_index(offsets, 1.179 ++ ntohl(head.num_blocks), ntohl(head.block_size))); 1.180 + 1.181 for (i = 0; i < ntohl(head.num_blocks); i++) { 1.182 - int currpos;