rev |
line source |
pascal@17000
|
1 --- cloop.h
|
pascal@17000
|
2 +++ cloop.h
|
pascal@17000
|
3 @@ -20,6 +20,74 @@
|
pascal@17000
|
4 /* data_index (num_blocks 64bit pointers, network order)... */
|
pascal@17000
|
5 /* compressed data (gzip block compressed format)... */
|
pascal@17000
|
6
|
pascal@17000
|
7 +struct cloop_tail
|
pascal@17000
|
8 +{
|
pascal@17000
|
9 + u_int32_t table_size;
|
pascal@17000
|
10 + u_int32_t index_size;
|
pascal@17000
|
11 + u_int32_t num_blocks;
|
pascal@17000
|
12 +};
|
pascal@17000
|
13 +
|
pascal@17000
|
14 +struct block_info
|
pascal@17000
|
15 +{
|
pascal@17000
|
16 + loff_t offset; /* 64-bit offsets of compressed block */
|
pascal@17000
|
17 + u_int32_t size; /* 32-bit compressed block size */
|
pascal@17000
|
18 + u_int32_t optidx; /* 32-bit index number */
|
pascal@17000
|
19 +};
|
pascal@17000
|
20 +
|
pascal@17000
|
21 +static inline char *build_index(struct block_info *offsets, unsigned long n)
|
pascal@17000
|
22 +{
|
pascal@17000
|
23 + u_int32_t *ofs32 = (u_int32_t *) offsets;
|
pascal@17000
|
24 + loff_t *ofs64 = (loff_t *) offsets;
|
pascal@17000
|
25 +
|
pascal@17000
|
26 + if (ofs32[0] == 0) {
|
pascal@17000
|
27 + if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */
|
pascal@17000
|
28 + while (n--) {
|
pascal@17000
|
29 + offsets[n].offset = __be64_to_cpu(offsets[n].offset);
|
pascal@17000
|
30 + offsets[n].size = ntohl(offsets[n].size);
|
pascal@17000
|
31 + }
|
pascal@17000
|
32 + return (char *) "128BE accelerated knoppix 1.0";
|
pascal@17000
|
33 + }
|
pascal@17000
|
34 + else { /* V2.0 */
|
pascal@17000
|
35 + loff_t last = __be64_to_cpu(ofs64[n]);
|
pascal@17000
|
36 + while (n--) {
|
pascal@17000
|
37 + offsets[n].size = last -
|
pascal@17000
|
38 + (offsets[n].offset = __be64_to_cpu(ofs64[n]));
|
pascal@17000
|
39 + last = offsets[n].offset;
|
pascal@17000
|
40 + }
|
pascal@17000
|
41 + return (char *) "64BE v2.0";
|
pascal@17000
|
42 + }
|
pascal@17000
|
43 + }
|
pascal@17000
|
44 + else if (ofs32[1] == 0) { /* V1.0 */
|
pascal@17000
|
45 + loff_t last = __le64_to_cpu(ofs64[n]);
|
pascal@17000
|
46 + while (n--) {
|
pascal@17000
|
47 + offsets[n].size = last -
|
pascal@17000
|
48 + (offsets[n].offset = __le64_to_cpu(ofs64[n]));
|
pascal@17000
|
49 + last = offsets[n].offset;
|
pascal@17000
|
50 + }
|
pascal@17000
|
51 + return (char *) "64LE v1.0";
|
pascal@17000
|
52 + }
|
pascal@17000
|
53 + else if (ntohl(ofs32[0]) == (4*n) + 0x8C) { /* V0.68 */
|
pascal@17000
|
54 + loff_t last = ntohl(ofs32[n]);
|
pascal@17000
|
55 + while (n--) {
|
pascal@17000
|
56 + offsets[n].size = last -
|
pascal@17000
|
57 + (offsets[n].offset = ntohl(ofs32[n]));
|
pascal@17000
|
58 + last = offsets[n].offset;
|
pascal@17000
|
59 + }
|
pascal@17000
|
60 + return (char *) "32BE v0.68";
|
pascal@17000
|
61 + }
|
pascal@17000
|
62 + else { /* V3.0 */
|
pascal@17000
|
63 + int i, j;
|
pascal@17000
|
64 +
|
pascal@17000
|
65 + for (i = n; i-- > 0; )
|
pascal@17000
|
66 + offsets[i].size = ntohl(ofs32[i]);
|
pascal@17000
|
67 + for (i = 0, j = sizeof(struct cloop_head); i < n; i++) {
|
pascal@17000
|
68 + offsets[i].offset = j;
|
pascal@17000
|
69 + j += offsets[i].size;
|
pascal@17000
|
70 + }
|
pascal@17000
|
71 + return (char *) "32BE v3.0";
|
pascal@17000
|
72 + }
|
pascal@17000
|
73 +}
|
pascal@17000
|
74 +
|
pascal@17000
|
75 /* Cloop suspend IOCTL */
|
pascal@17000
|
76 #define CLOOP_SUSPEND 0x4C07
|
pascal@17000
|
77
|
pascal@17000
|
78 --- cloop.c
|
pascal@17000
|
79 +++ cloop.c
|
pascal@17000
|
80 @@ -5,11 +5,18 @@
|
pascal@17000
|
81 * A cloop file looks like this:
|
pascal@17000
|
82 * [32-bit uncompressed block size: network order]
|
pascal@17000
|
83 * [32-bit number of blocks (n_blocks): network order]
|
pascal@17000
|
84 - * [64-bit file offsets of start of blocks: network order]
|
pascal@17000
|
85 + * [for version < 3]
|
pascal@17000
|
86 + * [32-bit, 64-bit or 128-bit file offsets of start of blocks]
|
pascal@17000
|
87 * ...
|
pascal@17000
|
88 * (n_blocks + 1).
|
pascal@17000
|
89 * n_blocks consisting of:
|
pascal@17000
|
90 * [compressed block]
|
pascal@17000
|
91 + * ...
|
pascal@17000
|
92 + * [for version >= 3]
|
pascal@17000
|
93 + * [compressed list of 32-bit block sizes]
|
pascal@17000
|
94 + * [32-bit compressed index size: network order]
|
pascal@17000
|
95 + * [32-bit index size = 4: network order]
|
pascal@17000
|
96 + * [32-bit number of blocks (n_blocks): network order]
|
pascal@17000
|
97 *
|
pascal@17000
|
98 * Every version greatly inspired by code seen in loop.c
|
pascal@17000
|
99 * by Theodore Ts'o, 3/29/93.
|
pascal@17000
|
100 @@ -115,7 +122,7 @@
|
pascal@17000
|
101 struct cloop_head head;
|
pascal@17000
|
102
|
pascal@17000
|
103 /* An array of offsets of compressed blocks within the file */
|
pascal@17000
|
104 - loff_t *offsets;
|
pascal@17000
|
105 + struct block_info *offsets;
|
pascal@17000
|
106
|
pascal@17000
|
107 /* We buffer some uncompressed blocks for performance */
|
pascal@17000
|
108 int buffered_blocknum[BUFFERED_BLOCKS];
|
pascal@17000
|
109 @@ -256,11 +263,11 @@
|
pascal@17000
|
110 return i;
|
pascal@17000
|
111 }
|
pascal@17000
|
112
|
pascal@17000
|
113 - buf_length = be64_to_cpu(clo->offsets[blocknum+1]) - be64_to_cpu(clo->offsets[blocknum]);
|
pascal@17000
|
114 + buf_length = clo->offsets[blocknum].size;
|
pascal@17000
|
115
|
pascal@17000
|
116 /* Load one compressed block from the file. */
|
pascal@17000
|
117 cloop_read_from_file(clo, clo->backing_file, (char *)clo->compressed_buffer,
|
pascal@17000
|
118 - be64_to_cpu(clo->offsets[blocknum]), buf_length);
|
pascal@17000
|
119 + clo->offsets[blocknum].offset, buf_length);
|
pascal@17000
|
120
|
pascal@17000
|
121 buflen = ntohl(clo->head.block_size);
|
pascal@17000
|
122
|
pascal@17000
|
123 @@ -275,9 +282,9 @@
|
pascal@17000
|
124 if (ret != 0)
|
pascal@17000
|
125 {
|
pascal@17000
|
126 printk(KERN_ERR "%s: zlib decompression error %i uncompressing block %u %u/%lu/%u/%u "
|
pascal@17000
|
127 - "%Lu-%Lu\n", cloop_name, ret, blocknum,
|
pascal@17000
|
128 + "%Lu:%u\n", cloop_name, ret, blocknum,
|
pascal@17000
|
129 ntohl(clo->head.block_size), buflen, buf_length, buf_done,
|
pascal@17000
|
130 - be64_to_cpu(clo->offsets[blocknum]), be64_to_cpu(clo->offsets[blocknum+1]));
|
pascal@17000
|
131 + clo->offsets[blocknum].offset, clo->offsets[blocknum].size);
|
pascal@17000
|
132 clo->buffered_blocknum[clo->current_bufnum] = -1;
|
pascal@17000
|
133 return -1;
|
pascal@17000
|
134 }
|
pascal@17000
|
135 @@ -489,30 +496,73 @@
|
pascal@17000
|
136 cloop_name, ntohl(clo->head.block_size));
|
pascal@17000
|
137 error=-EBADF; goto error_release;
|
pascal@17000
|
138 }
|
pascal@17000
|
139 - if (clo->head.preamble[0x0B]!='V'||clo->head.preamble[0x0C]<'1')
|
pascal@17000
|
140 - {
|
pascal@17000
|
141 - printk(KERN_ERR "%s: Cannot read old 32-bit (version 0.68) images, "
|
pascal@17000
|
142 - "please use an older version of %s for this file.\n",
|
pascal@17000
|
143 - cloop_name, cloop_name);
|
pascal@17000
|
144 - error=-EBADF; goto error_release;
|
pascal@17000
|
145 - }
|
pascal@17000
|
146 - if (clo->head.preamble[0x0C]<'2')
|
pascal@17000
|
147 - {
|
pascal@17000
|
148 - printk(KERN_ERR "%s: Cannot read old architecture-dependent "
|
pascal@17000
|
149 - "(format <= 1.0) images, please use an older "
|
pascal@17000
|
150 - "version of %s for this file.\n",
|
pascal@17000
|
151 - cloop_name, cloop_name);
|
pascal@17000
|
152 - error=-EBADF; goto error_release;
|
pascal@17000
|
153 - }
|
pascal@17000
|
154 - total_offsets=ntohl(clo->head.num_blocks)+1;
|
pascal@17000
|
155 - if (!isblkdev && (sizeof(struct cloop_head)+sizeof(loff_t)*
|
pascal@17000
|
156 + total_offsets=ntohl(clo->head.num_blocks);
|
pascal@17000
|
157 + if (!isblkdev && (sizeof(struct cloop_head)+sizeof(struct block_info)*
|
pascal@17000
|
158 total_offsets > inode->i_size))
|
pascal@17000
|
159 {
|
pascal@17000
|
160 printk(KERN_ERR "%s: file too small for %u blocks\n",
|
pascal@17000
|
161 cloop_name, ntohl(clo->head.num_blocks));
|
pascal@17000
|
162 error=-EBADF; goto error_release;
|
pascal@17000
|
163 }
|
pascal@17000
|
164 - clo->offsets = cloop_malloc(sizeof(loff_t) * total_offsets);
|
pascal@17000
|
165 + if (total_offsets + 1 == 0) /* Version >= 3.0 */
|
pascal@17000
|
166 + {
|
pascal@17000
|
167 + struct cloop_tail tail;
|
pascal@17000
|
168 + if(isblkdev)
|
pascal@17000
|
169 + {
|
pascal@17000
|
170 + /* No end of file: can't find index */
|
pascal@17000
|
171 + printk(KERN_ERR "%s: no V3 support for block device\n",
|
pascal@17000
|
172 + cloop_name);
|
pascal@17000
|
173 + error=-EBADF; goto error_release;
|
pascal@17000
|
174 + }
|
pascal@17000
|
175 + bytes_read = cloop_read_from_file(clo, file, (void *) &tail,
|
pascal@17000
|
176 + inode->i_size - sizeof(struct cloop_tail),
|
pascal@17000
|
177 + sizeof(struct cloop_tail));
|
pascal@17000
|
178 + if(bytes_read == sizeof(struct cloop_tail))
|
pascal@17000
|
179 + {
|
pascal@17000
|
180 + unsigned long len, zlen;
|
pascal@17000
|
181 + void *zbuf;
|
pascal@17000
|
182 + clo->head.num_blocks = tail.num_blocks;
|
pascal@17000
|
183 + total_offsets = ntohl(clo->head.num_blocks);
|
pascal@17000
|
184 + clo->offsets = cloop_malloc(sizeof(struct block_info) * total_offsets);
|
pascal@17000
|
185 + if (!clo->offsets)
|
pascal@17000
|
186 + {
|
pascal@17000
|
187 + printk(KERN_ERR "%s: can't alloc index\n",
|
pascal@17000
|
188 + cloop_name);
|
pascal@17000
|
189 + error=-EBADF; goto error_release;
|
pascal@17000
|
190 + }
|
pascal@17000
|
191 + zbuf = &clo->offsets[total_offsets/2];
|
pascal@17000
|
192 + zlen = ntohl(tail.table_size);
|
pascal@17000
|
193 + len = ntohl(tail.index_size) * total_offsets;
|
pascal@17000
|
194 + bytes_read = cloop_read_from_file(clo, file, zbuf,
|
pascal@17000
|
195 + inode->i_size - zlen - sizeof(struct cloop_tail),
|
pascal@17000
|
196 + zlen);
|
pascal@17000
|
197 + if (bytes_read != zlen)
|
pascal@17000
|
198 + {
|
pascal@17000
|
199 + printk(KERN_ERR "%s: can't read index\n",
|
pascal@17000
|
200 + cloop_name);
|
pascal@17000
|
201 + error=-EBADF; goto error_release;
|
pascal@17000
|
202 + }
|
pascal@17000
|
203 + clo->zstream.workspace = cloop_malloc(zlib_inflate_workspacesize());
|
pascal@17000
|
204 + if(!clo->zstream.workspace)
|
pascal@17000
|
205 + {
|
pascal@17000
|
206 + printk(KERN_ERR "%s: can't alloc index workspace\n",
|
pascal@17000
|
207 + cloop_name);
|
pascal@17000
|
208 + error=-EBADF; goto error_release;
|
pascal@17000
|
209 + }
|
pascal@17000
|
210 + zlib_inflateInit(&clo->zstream);
|
pascal@17000
|
211 + uncompress(clo, (void *) clo->offsets, &len, zbuf, zlen);
|
pascal@17000
|
212 + cloop_free(clo->zstream.workspace, zlib_inflate_workspacesize());
|
pascal@17000
|
213 + clo->zstream.workspace = NULL;
|
pascal@17000
|
214 + break;
|
pascal@17000
|
215 + }
|
pascal@17000
|
216 + else
|
pascal@17000
|
217 + {
|
pascal@17000
|
218 + printk(KERN_ERR "%s: can't find index\n",
|
pascal@17000
|
219 + cloop_name);
|
pascal@17000
|
220 + error=-EBADF; goto error_release;
|
pascal@17000
|
221 + }
|
pascal@17000
|
222 + }
|
pascal@17000
|
223 + clo->offsets = cloop_malloc(sizeof(struct block_info) * total_offsets);
|
pascal@17000
|
224 if (!clo->offsets)
|
pascal@17000
|
225 {
|
pascal@17000
|
226 printk(KERN_ERR "%s: out of kernel mem for offsets\n", cloop_name);
|
pascal@17000
|
227 @@ -521,19 +571,19 @@
|
pascal@17000
|
228 }
|
pascal@17000
|
229 num_readable = MIN(total_offsets - offsets_read,
|
pascal@17000
|
230 (clo->underlying_blksize - offset)
|
pascal@17000
|
231 - / sizeof(loff_t));
|
pascal@17000
|
232 - memcpy(&clo->offsets[offsets_read], bbuf+offset, num_readable * sizeof(loff_t));
|
pascal@17000
|
233 + / sizeof(struct block_info));
|
pascal@17000
|
234 + memcpy(&clo->offsets[offsets_read], bbuf+offset, num_readable * sizeof(struct block_info));
|
pascal@17000
|
235 offsets_read += num_readable;
|
pascal@17000
|
236 }
|
pascal@17000
|
237 { /* Search for largest block rather than estimate. KK. */
|
pascal@17000
|
238 int i;
|
pascal@17000
|
239 - for(i=0;i<total_offsets-1;i++)
|
pascal@17000
|
240 + char *version = build_index(clo->offsets, ntohl(clo->head.num_blocks));
|
pascal@17000
|
241 + for(i=0;i<total_offsets;i++)
|
pascal@17000
|
242 {
|
pascal@17000
|
243 - loff_t d=be64_to_cpu(clo->offsets[i+1]) - be64_to_cpu(clo->offsets[i]);
|
pascal@17000
|
244 - clo->largest_block=MAX(clo->largest_block,d);
|
pascal@17000
|
245 + clo->largest_block=MAX(clo->largest_block,clo->offsets[i].size);
|
pascal@17000
|
246 }
|
pascal@17000
|
247 - printk(KERN_INFO "%s: %s: %u blocks, %u bytes/block, largest block is %lu bytes.\n",
|
pascal@17000
|
248 - cloop_name, filename, ntohl(clo->head.num_blocks),
|
pascal@17000
|
249 + printk(KERN_INFO "%s: %s: %s, %u blocks, %u bytes/block, largest block is %lu bytes.\n",
|
pascal@17000
|
250 + cloop_name, filename, version, ntohl(clo->head.num_blocks),
|
pascal@17000
|
251 ntohl(clo->head.block_size), clo->largest_block);
|
pascal@17000
|
252 }
|
pascal@17000
|
253 /* Combo kmalloc used too large chunks (>130000). */
|
pascal@17000
|
254 @@ -565,16 +615,6 @@
|
pascal@17000
|
255 error=-ENOMEM; goto error_release_free_all;
|
pascal@17000
|
256 }
|
pascal@17000
|
257 zlib_inflateInit(&clo->zstream);
|
pascal@17000
|
258 - if(!isblkdev &&
|
pascal@17000
|
259 - be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]) != inode->i_size)
|
pascal@17000
|
260 - {
|
pascal@17000
|
261 - printk(KERN_ERR "%s: final offset wrong (%Lu not %Lu)\n",
|
pascal@17000
|
262 - cloop_name,
|
pascal@17000
|
263 - be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]),
|
pascal@17000
|
264 - inode->i_size);
|
pascal@17000
|
265 - cloop_free(clo->zstream.workspace, zlib_inflate_workspacesize()); clo->zstream.workspace=NULL;
|
pascal@17000
|
266 - goto error_release_free_all;
|
pascal@17000
|
267 - }
|
pascal@17000
|
268 {
|
pascal@17000
|
269 int i;
|
pascal@17000
|
270 for(i=0; i<BUFFERED_BLOCKS; i++) clo->buffered_blocknum[i] = -1;
|
pascal@17000
|
271 @@ -653,7 +693,7 @@
|
pascal@17000
|
272 }
|
pascal@17000
|
273 }
|
pascal@17000
|
274 error_release_free:
|
pascal@17000
|
275 - cloop_free(clo->offsets, sizeof(loff_t) * total_offsets);
|
pascal@17000
|
276 + cloop_free(clo->offsets, sizeof(struct block_info) * total_offsets);
|
pascal@17000
|
277 clo->offsets=NULL;
|
pascal@17000
|
278 error_release:
|
pascal@17000
|
279 if(bbuf) cloop_free(bbuf, clo->underlying_blksize);
|