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