wok view 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 source
1 --- compressed_loop.h
2 +++ compressed_loop.h
3 @@ -41,6 +41,55 @@
4 /* data_index (num_blocks 64bit pointers, network order)... */
5 /* compressed data (gzip block compressed format)... */
7 +struct block_info
8 +{
9 + loff_t offset; /* 64-bit offsets of compressed block */
10 + u_int32_t size; /* 32-bit compressed block size */
11 + u_int32_t optidx; /* 32-bit index number */
12 +};
13 +
14 +static inline char *build_index(struct block_info *offsets, unsigned long n)
15 +{
16 + u_int32_t *ofs32 = (u_int32_t *) offsets;
17 + loff_t *ofs64 = (loff_t *) offsets;
18 + if (ofs32[0] == 0) {
19 + if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */
20 + do {
21 + offsets[n].offset = __be64_to_cpu(offsets[n].offset);
22 + offsets[n].size = ntohl(offsets[n].size);
23 + } while (n--);
24 + return "128BE accelerated knoppix 1.0";
25 + }
26 + else { /* V2.0 */
27 + loff_t last = __be64_to_cpu(ofs64[n+1]);
28 + do {
29 + offsets[n].size = last -
30 + (offsets[n].offset = __be64_to_cpu(ofs64[n]));
31 + last = offsets[n].offset;
32 + } while (n--);
33 + return "64BE v2.0";
34 + }
35 + }
36 + else if (ofs32[1] == 0) { /* V1.0 */
37 + loff_t last = __be64_to_cpu(ofs64[n+1]);
38 + do {
39 + offsets[n].size = last -
40 + (offsets[n].offset = __le64_to_cpu(ofs64[n]));
41 + last = offsets[n].offset;
42 + } while (n--);
43 + return "64LE v1.0";
44 + }
45 + else { /* V0.68 */
46 + loff_t last = ntohl(ofs32[n+1]);
47 + do {
48 + offsets[n].size = last -
49 + (offsets[n].offset = ntohl(ofs32[n]));
50 + last = offsets[n].offset;
51 + } while (n--);
52 + return "32BE v0.68";
53 + }
54 +}
55 +
56 /* Cloop suspend IOCTL */
57 #define CLOOP_SUSPEND 0x4C07
60 --- cloopreader.h
61 +++ cloopreader.h
62 @@ -33,7 +33,7 @@
63 int numblocks;
64 ulong blocksize;
66 - loff_t* toc; /* Data index */
67 + struct block_info *toc; /* Data index */
68 size_t tocsize;
70 unsigned char* cblock; /* Compressed block */
72 --- cloopreader.c
73 +++ cloopreader.c
74 @@ -59,10 +59,11 @@
76 ALLOC(c->pblock,c->blocksize);
78 - c->tocsize=sizeof *c->toc * (c->numblocks+1); /* One extra address is position of EOF */
79 + c->tocsize=sizeof(*c->toc) * c->numblocks;
80 ALLOC(c->toc,c->tocsize);
82 OP(read_all(c->fh,c->toc,c->tocsize)); /* read Data Index */
83 + build_index(c->toc, c->numblocks);
84 c->cblocksizecur=0;
85 c->curblock=-1;
86 return 0;
87 @@ -79,10 +80,10 @@
88 if(page>=c->numblocks){errno=EFAULT;return -1;}
89 c->curblock=page;
91 - bprintf("Seeking to 0x%Lx\n",btc(c->toc[page]));
92 - OP(lseek(c->fh,btc(c->toc[page]), SEEK_SET));
93 + bprintf("Seeking to 0x%Lx\n",c->toc[page].offset);
94 + OP(lseek(c->fh,c->toc[page].offset, SEEK_SET));
96 - c->cblocksize=btc(c->toc[page+1]) - btc(c->toc[page]);
97 + c->cblocksize=c->toc[page].size;
98 bprintf("Compressed size=%lu\n",c->cblocksize);
99 if(c->cblocksize > c->cblocksizecur){
100 if(c->cblocksizecur)free(c->cblock);
101 --- extract_compressed_fs.c
102 +++ extract_compressed_fs.c
103 @@ -7,6 +7,7 @@
104 struct cloop_head head;
105 unsigned int i;
106 unsigned char *buffer, *clear_buffer;
107 + struct block_info *offsets;
109 if (argc != 2) {
110 fprintf(stderr, "Need filename\n");
111 @@ -30,35 +31,34 @@
112 fprintf(stderr, "%u blocks of size %u. Preamble:\n%s\n",
113 ntohl(head.num_blocks), ntohl(head.block_size), head.preamble);
115 + i = ntohl(head.num_blocks) * sizeof(*offsets);
116 + offsets = malloc(i);
117 + if (!offsets || read(handle, offsets, i) != i) {
118 + perror("Reading index\n");
119 + exit(1);
120 + }
121 +
122 + fprintf(stderr, "Index %s.\n",
123 + build_index(offsets, ntohl(head.num_blocks)));
124 +
125 for (i = 0; i < ntohl(head.num_blocks); i++) {
126 - int currpos;
127 unsigned long destlen = ntohl(head.block_size);
128 - loff_t offset[2];
129 - unsigned int size;
130 + unsigned int size = offsets[i].size;
132 - read(handle, &offset, 2*sizeof(loff_t));
133 - lseek(handle, -sizeof(loff_t), SEEK_CUR);
134 -
135 - currpos = lseek(handle, 0, SEEK_CUR);
136 - if (lseek(handle, __be64_to_cpu(offset[0]), SEEK_SET) < 0) {
137 + if (lseek(handle, offsets[i].offset, SEEK_SET) < 0) {
138 fprintf(stderr, "lseek to %Lu: %s\n",
139 - __be64_to_cpu(offset[0]), strerror(errno));
140 + offsets[i].offset, strerror(errno));
141 exit(1);
142 }
144 - size=__be64_to_cpu(offset[1])-__be64_to_cpu(offset[0]);
145 if (size > ntohl(head.block_size) + ntohl(head.block_size)/1000
146 + 12 + 4) {
147 fprintf(stderr,
148 "Size %u for block %u (offset %Lu) too big\n",
149 - size, i, __be64_to_cpu(offset[0]));
150 + size, i, offsets[i].offset);
151 exit(1);
152 }
153 read(handle, buffer, size);
154 - if (lseek(handle, currpos, SEEK_SET) < 0) {
155 - perror("seeking");
156 - exit(1);
157 - }
159 fprintf(stderr, "Block %u length %u => %lu\n",
160 i, size, destlen);