wok-current annotate linux64-cloop/stuff/cloop.u @ rev 18424

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