wok-current rev 17214
Add linux64-cloop
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Oct 10 17:14:27 2014 +0200 (2014-10-10) |
parents | c7c5267e7001 |
children | 6880673c44a1 |
files | linux-cloop/receipt linux64-cloop/receipt linux64-cloop/stuff/cloop.u |
line diff
1.1 --- a/linux-cloop/receipt Fri Oct 10 16:34:25 2014 +0200 1.2 +++ b/linux-cloop/receipt Fri Oct 10 17:14:27 2014 +0200 1.3 @@ -26,7 +26,7 @@ 1.4 # Rules to gen a SliTaz package suitable for Tazpkg. 1.5 genpkg_rules() 1.6 { 1.7 - EXTRAVERSION=_${kvers%.*} 1.8 + EXTRAVERSION=_$kvers 1.9 mkdir -p $fs/lib/modules/$kvers-slitaz/kernel/misc $fs/dev $fs/usr/bin 1.10 cp $src/cloop_suspend $fs/usr/bin 1.11 cp $src/cloop.ko.xz $fs/lib/modules/$kvers-slitaz/kernel/misc
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/linux64-cloop/receipt Fri Oct 10 17:14:27 2014 +0200 2.3 @@ -0,0 +1,50 @@ 2.4 +# SliTaz package receipt. 2.5 + 2.6 +PACKAGE="linux64-cloop" 2.7 +SOURCE="cloop" 2.8 +VERSION="2.639-2" 2.9 +CATEGORY="base-system" 2.10 +MAINTAINER="pascal.bellard@slitaz.org" 2.11 +LICENSE="GPL2" 2.12 +SHORT_DESC="The read-only compressed loop device kernel module." 2.13 +WEB_SITE="http://knoppix.net/wiki/Cloop" 2.14 +TARBALL="${SOURCE}_${VERSION}.tar.gz" 2.15 +WGET_URL="http://debian-knoppix.alioth.debian.org/packages/$SOURCE/$TARBALL" 2.16 +PROVIDE="linux-cloop:linux64" 2.17 + 2.18 +DEPENDS="linux64" 2.19 +BUILD_DEPENDS="linux-module-headers xz uclibc-cross-compiler-x86_64" 2.20 +SUGGESTED="cloop-utils" 2.21 + 2.22 +AUFS_NOT_RAMFS="uclibc-cross-compiler-x86_64 is not compatible with aufs+tmpfs 8(" 2.23 + 2.24 +# Rules to configure and make the package. 2.25 + 2.26 +compile_rules() 2.27 +{ 2.28 + patch -p0 < $stuff/cloop.u 2.29 + make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- KERNEL_DIR="/usr/src/linux" cloop.ko && xz cloop.ko 2.30 +} 2.31 + 2.32 +# Rules to gen a SliTaz package suitable for Tazpkg. 2.33 +genpkg_rules() 2.34 +{ 2.35 + EXTRAVERSION=_$kvers 2.36 + mkdir -p $fs/lib/modules/$kvers-slitaz64/kernel/misc $fs/dev $fs/usr/bin 2.37 + cp $src/cloop_suspend $fs/usr/bin 2.38 + cp $src/cloop.ko.xz $fs/lib/modules/$kvers-slitaz64/kernel/misc 2.39 + mknod $fs/dev/cloop b 240 0 2.40 + for i in $(seq 1 7); do 2.41 + mknod $fs/dev/cloop$i b 240 $i 2.42 + done 2.43 +} 2.44 + 2.45 +post_install() 2.46 +{ 2.47 + chroot "$1/" depmod -a ${EXTRAVERSION#_}-slitaz64 2.48 +} 2.49 + 2.50 +post_remove() 2.51 +{ 2.52 + depmod -a 2.53 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/linux64-cloop/stuff/cloop.u Fri Oct 10 17:14:27 2014 +0200 3.3 @@ -0,0 +1,280 @@ 3.4 +--- cloop.h 3.5 ++++ cloop.h 3.6 +@@ -20,6 +20,75 @@ 3.7 + /* data_index (num_blocks 64bit pointers, network order)... */ 3.8 + /* compressed data (gzip block compressed format)... */ 3.9 + 3.10 ++struct cloop_tail 3.11 ++{ 3.12 ++ u_int32_t table_size; 3.13 ++ u_int32_t index_size; 3.14 ++ u_int32_t num_blocks; 3.15 ++}; 3.16 ++ 3.17 ++struct block_info 3.18 ++{ 3.19 ++ loff_t offset; /* 64-bit offsets of compressed block */ 3.20 ++ u_int32_t size; /* 32-bit compressed block size */ 3.21 ++ u_int32_t optidx; /* 32-bit index number */ 3.22 ++}; 3.23 ++ 3.24 ++static inline char *build_index(struct block_info *offsets, unsigned long n) 3.25 ++{ 3.26 ++ u_int32_t *ofs32 = (u_int32_t *) offsets; 3.27 ++ loff_t *ofs64 = (loff_t *) offsets; 3.28 ++ 3.29 ++ if (ofs32[0] == 0) { 3.30 ++ if (ofs32[2]) { /* ACCELERATED KNOPPIX V1.0 */ 3.31 ++ while (n--) { 3.32 ++ offsets[n].offset = __be64_to_cpu(offsets[n].offset); 3.33 ++ offsets[n].size = ntohl(offsets[n].size); 3.34 ++ } 3.35 ++ return (char *) "128BE accelerated knoppix 1.0"; 3.36 ++ } 3.37 ++ else { /* V2.0 */ 3.38 ++ loff_t last = __be64_to_cpu(ofs64[n]); 3.39 ++ while (n--) { 3.40 ++ offsets[n].size = last - 3.41 ++ (offsets[n].offset = __be64_to_cpu(ofs64[n])); 3.42 ++ last = offsets[n].offset; 3.43 ++ } 3.44 ++ return (char *) "64BE v2.0"; 3.45 ++ } 3.46 ++ } 3.47 ++ else if (ofs32[1] == 0) { /* V1.0 */ 3.48 ++ loff_t last = __le64_to_cpu(ofs64[n]); 3.49 ++ while (n--) { 3.50 ++ offsets[n].size = last - 3.51 ++ (offsets[n].offset = __le64_to_cpu(ofs64[n])); 3.52 ++ last = offsets[n].offset; 3.53 ++ } 3.54 ++ return (char *) "64LE v1.0"; 3.55 ++ } 3.56 ++ else if (ntohl(ofs32[0]) == (4*n) + 0x8C) { /* V0.68 */ 3.57 ++ loff_t last = ntohl(ofs32[n]); 3.58 ++ while (n--) { 3.59 ++ offsets[n].size = last - 3.60 ++ (offsets[n].offset = ntohl(ofs32[n])); 3.61 ++ last = offsets[n].offset; 3.62 ++ } 3.63 ++ return (char *) "32BE v0.68"; 3.64 ++ } 3.65 ++ else { /* V3.0 */ 3.66 ++ unsigned long i; 3.67 ++ loff_t j; 3.68 ++ 3.69 ++ for (i = n; i-- != 0; ) 3.70 ++ offsets[i].size = ntohl(ofs32[i]); 3.71 ++ for (i = 0, j = sizeof(struct cloop_head); i < n; i++) { 3.72 ++ offsets[i].offset = j; 3.73 ++ j += offsets[i].size; 3.74 ++ } 3.75 ++ return (char *) "32BE v3.0"; 3.76 ++ } 3.77 ++} 3.78 ++ 3.79 + /* Cloop suspend IOCTL */ 3.80 + #define CLOOP_SUSPEND 0x4C07 3.81 + 3.82 +--- cloop.c 3.83 ++++ cloop.c 3.84 +@@ -5,11 +5,18 @@ 3.85 + * A cloop file looks like this: 3.86 + * [32-bit uncompressed block size: network order] 3.87 + * [32-bit number of blocks (n_blocks): network order] 3.88 +- * [64-bit file offsets of start of blocks: network order] 3.89 ++ * [for version < 3] 3.90 ++ * [32-bit, 64-bit or 128-bit file offsets of start of blocks] 3.91 + * ... 3.92 + * (n_blocks + 1). 3.93 + * n_blocks consisting of: 3.94 + * [compressed block] 3.95 ++ * ... 3.96 ++ * [for version >= 3] 3.97 ++ * [compressed list of 32-bit block sizes] 3.98 ++ * [32-bit compressed index size: network order] 3.99 ++ * [32-bit index size = 4: network order] 3.100 ++ * [32-bit number of blocks (n_blocks): network order] 3.101 + * 3.102 + * Every version greatly inspired by code seen in loop.c 3.103 + * by Theodore Ts'o, 3/29/93. 3.104 +@@ -115,7 +122,7 @@ 3.105 + struct cloop_head head; 3.106 + 3.107 + /* An array of offsets of compressed blocks within the file */ 3.108 +- loff_t *offsets; 3.109 ++ struct block_info *offsets; 3.110 + 3.111 + /* We buffer some uncompressed blocks for performance */ 3.112 + int buffered_blocknum[BUFFERED_BLOCKS]; 3.113 +@@ -256,11 +263,11 @@ 3.114 + return i; 3.115 + } 3.116 + 3.117 +- buf_length = be64_to_cpu(clo->offsets[blocknum+1]) - be64_to_cpu(clo->offsets[blocknum]); 3.118 ++ buf_length = clo->offsets[blocknum].size; 3.119 + 3.120 + /* Load one compressed block from the file. */ 3.121 + cloop_read_from_file(clo, clo->backing_file, (char *)clo->compressed_buffer, 3.122 +- be64_to_cpu(clo->offsets[blocknum]), buf_length); 3.123 ++ clo->offsets[blocknum].offset, buf_length); 3.124 + 3.125 + buflen = ntohl(clo->head.block_size); 3.126 + 3.127 +@@ -275,9 +282,9 @@ 3.128 + if (ret != 0) 3.129 + { 3.130 + printk(KERN_ERR "%s: zlib decompression error %i uncompressing block %u %u/%lu/%u/%u " 3.131 +- "%Lu-%Lu\n", cloop_name, ret, blocknum, 3.132 ++ "%Lu:%u\n", cloop_name, ret, blocknum, 3.133 + ntohl(clo->head.block_size), buflen, buf_length, buf_done, 3.134 +- be64_to_cpu(clo->offsets[blocknum]), be64_to_cpu(clo->offsets[blocknum+1])); 3.135 ++ clo->offsets[blocknum].offset, clo->offsets[blocknum].size); 3.136 + clo->buffered_blocknum[clo->current_bufnum] = -1; 3.137 + return -1; 3.138 + } 3.139 +@@ -489,30 +496,73 @@ 3.140 + cloop_name, ntohl(clo->head.block_size)); 3.141 + error=-EBADF; goto error_release; 3.142 + } 3.143 +- if (clo->head.preamble[0x0B]!='V'||clo->head.preamble[0x0C]<'1') 3.144 +- { 3.145 +- printk(KERN_ERR "%s: Cannot read old 32-bit (version 0.68) images, " 3.146 +- "please use an older version of %s for this file.\n", 3.147 +- cloop_name, cloop_name); 3.148 +- error=-EBADF; goto error_release; 3.149 +- } 3.150 +- if (clo->head.preamble[0x0C]<'2') 3.151 +- { 3.152 +- printk(KERN_ERR "%s: Cannot read old architecture-dependent " 3.153 +- "(format <= 1.0) images, please use an older " 3.154 +- "version of %s for this file.\n", 3.155 +- cloop_name, cloop_name); 3.156 +- error=-EBADF; goto error_release; 3.157 +- } 3.158 +- total_offsets=ntohl(clo->head.num_blocks)+1; 3.159 +- if (!isblkdev && (sizeof(struct cloop_head)+sizeof(loff_t)* 3.160 ++ total_offsets=ntohl(clo->head.num_blocks); 3.161 ++ if (!isblkdev && (sizeof(struct cloop_head)+sizeof(struct block_info)* 3.162 + total_offsets > inode->i_size)) 3.163 + { 3.164 + printk(KERN_ERR "%s: file too small for %u blocks\n", 3.165 + cloop_name, ntohl(clo->head.num_blocks)); 3.166 + error=-EBADF; goto error_release; 3.167 + } 3.168 +- clo->offsets = cloop_malloc(sizeof(loff_t) * total_offsets); 3.169 ++ if (total_offsets + 1 == 0) /* Version >= 3.0 */ 3.170 ++ { 3.171 ++ struct cloop_tail tail; 3.172 ++ if(isblkdev) 3.173 ++ { 3.174 ++ /* No end of file: can't find index */ 3.175 ++ printk(KERN_ERR "%s: no V3 support for block device\n", 3.176 ++ cloop_name); 3.177 ++ error=-EBADF; goto error_release; 3.178 ++ } 3.179 ++ bytes_read = cloop_read_from_file(clo, file, (void *) &tail, 3.180 ++ inode->i_size - sizeof(struct cloop_tail), 3.181 ++ sizeof(struct cloop_tail)); 3.182 ++ if(bytes_read == sizeof(struct cloop_tail)) 3.183 ++ { 3.184 ++ unsigned long len, zlen; 3.185 ++ void *zbuf; 3.186 ++ clo->head.num_blocks = tail.num_blocks; 3.187 ++ total_offsets = ntohl(clo->head.num_blocks); 3.188 ++ clo->offsets = cloop_malloc(sizeof(struct block_info) * total_offsets); 3.189 ++ if (!clo->offsets) 3.190 ++ { 3.191 ++ printk(KERN_ERR "%s: can't alloc index\n", 3.192 ++ cloop_name); 3.193 ++ error=-EBADF; goto error_release; 3.194 ++ } 3.195 ++ zbuf = &clo->offsets[total_offsets/2]; 3.196 ++ zlen = ntohl(tail.table_size); 3.197 ++ len = ntohl(tail.index_size) * total_offsets; 3.198 ++ bytes_read = cloop_read_from_file(clo, file, zbuf, 3.199 ++ inode->i_size - zlen - sizeof(struct cloop_tail), 3.200 ++ zlen); 3.201 ++ if (bytes_read != zlen) 3.202 ++ { 3.203 ++ printk(KERN_ERR "%s: can't read index\n", 3.204 ++ cloop_name); 3.205 ++ error=-EBADF; goto error_release; 3.206 ++ } 3.207 ++ clo->zstream.workspace = cloop_malloc(zlib_inflate_workspacesize()); 3.208 ++ if(!clo->zstream.workspace) 3.209 ++ { 3.210 ++ printk(KERN_ERR "%s: can't alloc index workspace\n", 3.211 ++ cloop_name); 3.212 ++ error=-EBADF; goto error_release; 3.213 ++ } 3.214 ++ zlib_inflateInit(&clo->zstream); 3.215 ++ uncompress(clo, (void *) clo->offsets, &len, zbuf, zlen); 3.216 ++ cloop_free(clo->zstream.workspace, zlib_inflate_workspacesize()); 3.217 ++ clo->zstream.workspace = NULL; 3.218 ++ break; 3.219 ++ } 3.220 ++ else 3.221 ++ { 3.222 ++ printk(KERN_ERR "%s: can't find index\n", 3.223 ++ cloop_name); 3.224 ++ error=-EBADF; goto error_release; 3.225 ++ } 3.226 ++ } 3.227 ++ clo->offsets = cloop_malloc(sizeof(struct block_info) * total_offsets); 3.228 + if (!clo->offsets) 3.229 + { 3.230 + printk(KERN_ERR "%s: out of kernel mem for offsets\n", cloop_name); 3.231 +@@ -521,19 +571,19 @@ 3.232 + } 3.233 + num_readable = MIN(total_offsets - offsets_read, 3.234 + (clo->underlying_blksize - offset) 3.235 +- / sizeof(loff_t)); 3.236 +- memcpy(&clo->offsets[offsets_read], bbuf+offset, num_readable * sizeof(loff_t)); 3.237 ++ / sizeof(struct block_info)); 3.238 ++ memcpy(&clo->offsets[offsets_read], bbuf+offset, num_readable * sizeof(struct block_info)); 3.239 + offsets_read += num_readable; 3.240 + } 3.241 + { /* Search for largest block rather than estimate. KK. */ 3.242 + int i; 3.243 +- for(i=0;i<total_offsets-1;i++) 3.244 ++ char *version = build_index(clo->offsets, ntohl(clo->head.num_blocks)); 3.245 ++ for(i=0;i<total_offsets;i++) 3.246 + { 3.247 +- loff_t d=be64_to_cpu(clo->offsets[i+1]) - be64_to_cpu(clo->offsets[i]); 3.248 +- clo->largest_block=MAX(clo->largest_block,d); 3.249 ++ clo->largest_block=MAX(clo->largest_block,clo->offsets[i].size); 3.250 + } 3.251 +- printk(KERN_INFO "%s: %s: %u blocks, %u bytes/block, largest block is %lu bytes.\n", 3.252 +- cloop_name, filename, ntohl(clo->head.num_blocks), 3.253 ++ printk(KERN_INFO "%s: %s: %s, %u blocks, %u bytes/block, largest block is %lu bytes.\n", 3.254 ++ cloop_name, filename, version, ntohl(clo->head.num_blocks), 3.255 + ntohl(clo->head.block_size), clo->largest_block); 3.256 + } 3.257 + /* Combo kmalloc used too large chunks (>130000). */ 3.258 +@@ -565,16 +615,6 @@ 3.259 + error=-ENOMEM; goto error_release_free_all; 3.260 + } 3.261 + zlib_inflateInit(&clo->zstream); 3.262 +- if(!isblkdev && 3.263 +- be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]) != inode->i_size) 3.264 +- { 3.265 +- printk(KERN_ERR "%s: final offset wrong (%Lu not %Lu)\n", 3.266 +- cloop_name, 3.267 +- be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]), 3.268 +- inode->i_size); 3.269 +- cloop_free(clo->zstream.workspace, zlib_inflate_workspacesize()); clo->zstream.workspace=NULL; 3.270 +- goto error_release_free_all; 3.271 +- } 3.272 + { 3.273 + int i; 3.274 + for(i=0; i<BUFFERED_BLOCKS; i++) clo->buffered_blocknum[i] = -1; 3.275 +@@ -653,7 +693,7 @@ 3.276 + } 3.277 + } 3.278 + error_release_free: 3.279 +- cloop_free(clo->offsets, sizeof(loff_t) * total_offsets); 3.280 ++ cloop_free(clo->offsets, sizeof(struct block_info) * total_offsets); 3.281 + clo->offsets=NULL; 3.282 + error_release: 3.283 + if(bbuf) cloop_free(bbuf, clo->underlying_blksize);