wok view fusecloop/stuff/fusecloop.u @ rev 10934

fusecloop: fix compile_rules
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Aug 26 20:47:01 2011 +0200 (2011-08-26)
parents ff0097ff50cd
children 65b7fa14f14f
line source
1 --- compressed_loop.h
2 +++ compressed_loop.h
3 @@ -41,6 +41,85 @@
4 /* data_index (num_blocks 64bit pointers, network order)... */
5 /* compressed data (gzip block compressed format)... */
7 +struct cloop_tail
8 +{
9 + u_int32_t index_size;
10 + u_int32_t num_blocks;
11 +};
12 +
13 +struct block_info
14 +{
15 + loff_t offset; /* 64-bit offsets of compressed block */
16 + u_int32_t size; /* 32-bit compressed block size */
17 + u_int32_t optidx; /* 32-bit index number */
18 +};
19 +
20 +static inline char *build_index(struct block_info *offsets, unsigned long n,
21 + unsigned long block_size)
22 +{
23 + u_int16_t *ofs16 = (u_int16_t *) offsets;
24 + u_int32_t *ofs32 = (u_int32_t *) offsets;
25 + loff_t *ofs64 = (loff_t *) offsets;
26 +
27 + if (ofs32[0] == 0) {
28 + if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */
29 + while (n--) {
30 + offsets[n].offset = __be64_to_cpu(offsets[n].offset);
31 + offsets[n].size = ntohl(offsets[n].size);
32 + }
33 + return "128BE accelerated knoppix 1.0";
34 + }
35 + else { /* V2.0 */
36 + loff_t last = __be64_to_cpu(ofs64[n]);
37 + while (n--) {
38 + offsets[n].size = last -
39 + (offsets[n].offset = __be64_to_cpu(ofs64[n]));
40 + last = offsets[n].offset;
41 + }
42 + return "64BE v2.0";
43 + }
44 + }
45 + else if (ofs32[1] == 0) { /* V1.0 */
46 + loff_t last = __be64_to_cpu(ofs64[n]);
47 + while (n--) {
48 + offsets[n].size = last -
49 + (offsets[n].offset = __le64_to_cpu(ofs64[n]));
50 + last = offsets[n].offset;
51 + }
52 + return "64LE v1.0";
53 + }
54 + else if (ntohl(ofs32[0]) == (4*n) + 0x8C) { /* V0.68 */
55 + loff_t last = ntohl(ofs32[n]);
56 + while (n--) {
57 + offsets[n].size = last -
58 + (offsets[n].offset = ntohl(ofs32[n]));
59 + last = offsets[n].offset;
60 + }
61 + return "32BE v0.68";
62 + }
63 + else { /* V3.0 */
64 + char *type;
65 + int i, j, smallest;
66 +
67 + smallest = (block_size < 32768) ? 0 : block_size>>10;
68 + if (block_size > 0x10000) {
69 + for (i = 0; i < n; i++)
70 + offsets[n].size = smallest + ntohl(ofs32[n]);
71 + type = "32BE size v3.0";
72 + }
73 + else {
74 + for (i = 0; i < n; i++)
75 + offsets[n].size = smallest + ntohs(ofs16[n]);
76 + type = "16BE size v3.0";
77 + }
78 + for (i = j = 0; i < n; i++) {
79 + offsets[i].offset = j;
80 + j += offsets[i].size;
81 + }
82 + return type;
83 + }
84 +}
85 +
86 /* Cloop suspend IOCTL */
87 #define CLOOP_SUSPEND 0x4C07
90 --- cloopreader.h
91 +++ cloopreader.h
92 @@ -33,7 +33,7 @@
93 int numblocks;
94 ulong blocksize;
96 - loff_t* toc; /* Data index */
97 + struct block_info *toc; /* Data index */
98 size_t tocsize;
100 unsigned char* cblock; /* Compressed block */
102 --- cloopreader.c
103 +++ cloopreader.c
104 @@ -59,10 +59,20 @@
106 ALLOC(c->pblock,c->blocksize);
108 - c->tocsize=sizeof *c->toc * (c->numblocks+1); /* One extra address is position of EOF */
109 + c->tocsize=sizeof(*c->toc) * c->numblocks;
110 + if (c->numblocks == -1) {
111 + struct cloop_tail tail;
112 +
113 + OP(lseek(c->fh, - sizeof(tail), SEEK_END));
114 + OP(read_all(c->fh, &tail, sizeof(tail)));
115 + c->numblocks = ntohl(tail.num_blocks);
116 + c->tocsize = ntohl(tail.index_size) * c->numblocks;
117 + OP(lseek(c->fh, - sizeof(tail) - c->tocsize, SEEK_END));
118 + }
119 ALLOC(c->toc,c->tocsize);
121 OP(read_all(c->fh,c->toc,c->tocsize)); /* read Data Index */
122 + build_index(c->toc, c->numblocks, c->blocksize);
123 c->cblocksizecur=0;
124 c->curblock=-1;
125 return 0;
126 @@ -79,10 +89,10 @@
127 if(page>=c->numblocks){errno=EFAULT;return -1;}
128 c->curblock=page;
130 - bprintf("Seeking to 0x%Lx\n",btc(c->toc[page]));
131 - OP(lseek(c->fh,btc(c->toc[page]), SEEK_SET));
132 + bprintf("Seeking to 0x%Lx\n",c->toc[page].offset);
133 + OP(lseek(c->fh,c->toc[page].offset, SEEK_SET));
135 - c->cblocksize=btc(c->toc[page+1]) - btc(c->toc[page]);
136 + c->cblocksize=c->toc[page].size;
137 bprintf("Compressed size=%lu\n",c->cblocksize);
138 if(c->cblocksize > c->cblocksizecur){
139 if(c->cblocksizecur)free(c->cblock);
141 --- extract_compressed_fs.c
142 +++ extract_compressed_fs.c
143 @@ -7,6 +7,7 @@
144 struct cloop_head head;
145 unsigned int i;
146 unsigned char *buffer, *clear_buffer;
147 + struct block_info *offsets;
149 if (argc != 2) {
150 fprintf(stderr, "Need filename\n");
151 @@ -30,35 +31,48 @@
152 fprintf(stderr, "%u blocks of size %u. Preamble:\n%s\n",
153 ntohl(head.num_blocks), ntohl(head.block_size), head.preamble);
155 + i = ntohl(head.num_blocks);
156 + if (i == -1) {
157 + struct cloop_tail tail;
158 + if (lseek(handle, - sizeof(tail), SEEK_END) < 0 ||
159 + read(handle, &tail, sizeof(tail)) != sizeof(tail) ||
160 + lseek(handle, - sizeof(tail) -
161 + (ntohl(tail.num_blocks) * ntohl(tail.index_size)),
162 + SEEK_END) < 0) {
163 + perror("Reading tail\n");
164 + exit(1);
165 + }
166 + head.num_blocks = tail.num_blocks;
167 + i = ntohl(tail.num_blocks) * ntohl(tail.index_size);
168 + }
169 + else i *= sizeof(*offsets);
170 + offsets = malloc(i);
171 + if (!offsets || read(handle, offsets, i) != i) {
172 + perror("Reading index\n");
173 + exit(1);
174 + }
175 +
176 + fprintf(stderr, "Index %s.\n", build_index(offsets,
177 + ntohl(head.num_blocks), ntohl(head.block_size)));
178 +
179 for (i = 0; i < ntohl(head.num_blocks); i++) {
180 - int currpos;
181 unsigned long destlen = ntohl(head.block_size);
182 - loff_t offset[2];
183 - unsigned int size;
184 + unsigned int size = offsets[i].size;
186 - read(handle, &offset, 2*sizeof(loff_t));
187 - lseek(handle, -sizeof(loff_t), SEEK_CUR);
188 -
189 - currpos = lseek(handle, 0, SEEK_CUR);
190 - if (lseek(handle, __be64_to_cpu(offset[0]), SEEK_SET) < 0) {
191 + if (lseek(handle, offsets[i].offset, SEEK_SET) < 0) {
192 fprintf(stderr, "lseek to %Lu: %s\n",
193 - __be64_to_cpu(offset[0]), strerror(errno));
194 + offsets[i].offset, strerror(errno));
195 exit(1);
196 }
198 - size=__be64_to_cpu(offset[1])-__be64_to_cpu(offset[0]);
199 if (size > ntohl(head.block_size) + ntohl(head.block_size)/1000
200 + 12 + 4) {
201 fprintf(stderr,
202 "Size %u for block %u (offset %Lu) too big\n",
203 - size, i, __be64_to_cpu(offset[0]));
204 + size, i, offsets[i].offset);
205 exit(1);
206 }
207 read(handle, buffer, size);
208 - if (lseek(handle, currpos, SEEK_SET) < 0) {
209 - perror("seeking");
210 - exit(1);
211 - }
213 fprintf(stderr, "Block %u length %u => %lu\n",
214 i, size, destlen);