wok-current rev 17996
fusecloop: adjust size
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Apr 24 18:41:32 2015 +0200 (2015-04-24) |
parents | 0f14c2f0b7d9 |
children | 153fb93a12da |
files | fusecloop/stuff/fusecloop.u |
line diff
1.1 --- a/fusecloop/stuff/fusecloop.u Fri Apr 24 16:39:12 2015 +0300 1.2 +++ b/fusecloop/stuff/fusecloop.u Fri Apr 24 18:41:32 2015 +0200 1.3 @@ -155,7 +155,7 @@ 1.4 int handle; 1.5 struct cloop_head head; 1.6 unsigned int i; 1.7 -+ unsigned long num_blocks, block_size, zblock_maxsize; 1.8 ++ unsigned long num_blocks, block_size, zblock_maxsize, lastlen = 0; 1.9 unsigned char *buffer, *clear_buffer; 1.10 + struct block_info *offsets; 1.11 1.12 @@ -171,7 +171,7 @@ 1.13 if (handle < 0) { 1.14 perror("Opening compressed file\n"); 1.15 exit(1); 1.16 -@@ -24,44 +28,99 @@ 1.17 +@@ -24,44 +28,100 @@ 1.18 exit(1); 1.19 } 1.20 1.21 @@ -209,6 +209,7 @@ 1.22 + table_size = ntohl(tail.table_size); 1.23 + table = malloc(table_size); 1.24 + len = i = num_blocks * (ntohl(tail.index_size) & 255); 1.25 ++ lastlen = ntohl(tail.index_size) / 256; 1.26 + offsets = malloc(num_blocks * sizeof(*offsets)); 1.27 + if (!table || !offsets || 1.28 + read(handle, table, table_size) != table_size || 1.29 @@ -297,7 +298,7 @@ 1.30 if (i == 3) { 1.31 fprintf(stderr, 1.32 "Block head:%02X%02X%02X%02X%02X%02X%02X%02X\n", 1.33 -@@ -105,12 +164,12 @@ 1.34 +@@ -105,12 +165,12 @@ 1.35 fprintf(stderr, "Uncomp: unknown error %u\n", i); 1.36 exit(1); 1.37 } 1.38 @@ -310,7 +311,7 @@ 1.39 exit(1); 1.40 } 1.41 - write(STDOUT_FILENO, clear_buffer, ntohl(head.block_size)); 1.42 -+ write(STDOUT_FILENO, clear_buffer, block_size); 1.43 ++ write(STDOUT_FILENO, clear_buffer, (lastlen != 0 && (i+1) == num_blocks) ? lastlen : block_size); 1.44 } 1.45 return 0; 1.46 } 1.47 @@ -343,7 +344,7 @@ 1.48 1.49 --- create_compressed_fs.c 1.50 +++ create_compressed_fs.c 1.51 -@@ -0,0 +1,147 @@ 1.52 +@@ -0,0 +1,149 @@ 1.53 +#ifdef FIND_BEST_COMPRESSION 1.54 +#include <compress.h> 1.55 +extern "C" { 1.56 @@ -429,7 +430,7 @@ 1.57 + unsigned char *compressed, *uncompressed; 1.58 + unsigned long *index; 1.59 + int n, indexmax, zlenmax; 1.60 -+ unsigned long len, pos; 1.61 ++ unsigned long lastlen, len, pos; 1.62 + static char padding[512]; 1.63 + 1.64 + if (argc > 1) { 1.65 @@ -455,7 +456,8 @@ 1.66 + if (!compressed || !uncompressed || !index) 1.67 + quit("Malloc failed"); 1.68 + 1.69 -+ for (n = 0; readblock(uncompressed, block_size); n++) { 1.70 ++ for (n = 0; (len = readblock(uncompressed, block_size)) != 0; n++) { 1.71 ++ if (len) lastlen = len; 1.72 + len = zlenmax; 1.73 + if (compress2(compressed, &len, uncompressed, block_size, 1.74 + Z_BEST_COMPRESSION) != Z_OK) 1.75 @@ -472,7 +474,8 @@ 1.76 + } 1.77 + index[n] = ntohl(len); 1.78 + } 1.79 -+ tail.index_size = ntohl(sizeof(*index)); 1.80 ++ if (block_size >= 0x1000000) lastlen = 0; 1.81 ++ tail.index_size = ntohl(sizeof(*index) + 256*(lastlen % 0xFFffFF)); 1.82 + tail.num_blocks = ntohl(n); 1.83 + n *= sizeof(*index); 1.84 + len = n + n/1000 + 12;