Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 207737 | Differences between
and this patch

Collapse All | Expand All

(-)linux-2.6.25-gentoo-r8.orig/fs/Kconfig (+1 lines)
Lines 1372-1377 Link Here
1372
config SQUASHFS
1372
config SQUASHFS
1373
	tristate "SquashFS 3.3 - Squashed file system support"
1373
	tristate "SquashFS 3.3 - Squashed file system support"
1374
	select ZLIB_INFLATE
1374
	select ZLIB_INFLATE
1375
	select LZMA
1375
	help
1376
	help
1376
	  Saying Y here includes support for SquashFS 3.3 (a Compressed
1377
	  Saying Y here includes support for SquashFS 3.3 (a Compressed
1377
	  Read-Only File System).  Squashfs is a highly compressed read-only
1378
	  Read-Only File System).  Squashfs is a highly compressed read-only
(-)linux-2.6.25-gentoo-r8.orig/fs/squashfs/inode.c (-71 / +183 lines)
Lines 35-42 Link Here
35
#include <linux/sched.h>
35
#include <linux/sched.h>
36
36
37
#include "squashfs.h"
37
#include "squashfs.h"
38
#include "../../lib/lzma/sqlzma.h"
39
#include "sqmagic.h"
38
40
39
int squashfs_cached_blks;
41
#undef KeepPreemptive
42
#if defined(CONFIG_PREEMPT) && !defined(UnsquashNoPreempt)
43
#define KeepPreemptive
44
#endif
45
46
struct sqlzma {
47
#ifdef KeepPreemptive
48
	struct mutex mtx;
49
#endif
50
	unsigned char read_data[SQUASHFS_FILE_MAX_SIZE];
51
	struct sqlzma_un un;
52
};
53
static DEFINE_PER_CPU(struct sqlzma *, sqlzma);
54
55
#define dpri(fmt, args...) /* printk("%s:%d: " fmt, __func__, __LINE__, ##args) */
56
#define dpri_un(un)	dpri("un{%d, {%d %p}, {%d %p}, {%d %p}}\n", \
57
			     (un)->un_lzma, (un)->un_a[0].sz, (un)->un_a[0].buf, \
58
			     (un)->un_a[1].sz, (un)->un_a[1].buf, \
59
			     (un)->un_a[2].sz, (un)->un_a[2].buf)
60
61
static int squashfs_cached_blks;
40
62
41
static struct dentry *squashfs_get_parent(struct dentry *child);
63
static struct dentry *squashfs_get_parent(struct dentry *child);
42
static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
64
static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
Lines 242-276 Link Here
242
	}
264
	}
243
265
244
	if (compressed) {
266
	if (compressed) {
245
		int zlib_err = 0;
267
		int zlib_err = Z_STREAM_END;
268
		int start;
269
		enum {Src, Dst};
270
		struct sized_buf sbuf[2];
271
		struct sqlzma *percpu;
272
		unsigned char *p;
246
273
247
		/*
274
		/*
248
	 	* uncompress block
275
	 	* uncompress block
249
	 	*/
276
	 	*/
250
277
251
		mutex_lock(&msblk->read_data_mutex);
278
		/* mutex_lock(&msblk->read_data_mutex); */
252
253
		msblk->stream.next_out = buffer;
254
		msblk->stream.avail_out = srclength;
255
256
		for (bytes = 0; k < b; k++) {
257
			avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
258
279
280
		start = k;
281
		for (; k < b; k++) {
259
			wait_on_buffer(bh[k]);
282
			wait_on_buffer(bh[k]);
260
			if (!buffer_uptodate(bh[k]))
283
			if (!buffer_uptodate(bh[k]))
261
				goto release_mutex;
284
				goto release_mutex;
285
		}
262
286
263
			msblk->stream.next_in = bh[k]->b_data + offset;
287
		/* it disables preemption */
264
			msblk->stream.avail_in = avail_bytes;
288
		percpu = get_cpu_var(sqlzma);
289
#ifdef KeepPreemptive
290
		put_cpu_var(sqlzma);
291
		mutex_lock(&percpu->mtx);
292
#endif
293
		p = percpu->read_data;
294
		k = start;
295
		for (bytes = 0; k < b; k++) {
296
			avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
265
297
266
			if (k == 0) {
298
			if (k == 0) {
267
				zlib_err = zlib_inflateInit(&msblk->stream);
299
				/*
268
				if (zlib_err != Z_OK) {
300
				 * keep this block structture to simplify the
269
					ERROR("zlib_inflateInit returned unexpected result 0x%x,"
301
				 * diff.
270
						" srclength %d\n", zlib_err, srclength);
302
				 */
271
					goto release_mutex;
272
				}
273
274
				if (avail_bytes == 0) {
303
				if (avail_bytes == 0) {
275
					offset = 0;
304
					offset = 0;
276
					brelse(bh[k]);
305
					brelse(bh[k]);
Lines 278-307 Link Here
278
				}
307
				}
279
			}
308
			}
280
309
281
			zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
310
			memcpy(p, bh[k]->b_data + offset, avail_bytes);
282
			if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
311
			p += avail_bytes;
283
				ERROR("zlib_inflate returned unexpected result 0x%x,"
312
#if 0
284
					" srclength %d, avail_in %d, avail_out %d\n", zlib_err,
313
			BUG_ON(percpu->read_data + sizeof(percpu->read_data)
285
					srclength, msblk->stream.avail_in, msblk->stream.avail_out);
314
			       < p);
286
				goto release_mutex;
315
#endif
287
			}
288
316
289
			bytes += avail_bytes;
317
			bytes += avail_bytes;
290
			offset = 0;
318
			offset = 0;
291
			brelse(bh[k]);
319
			brelse(bh[k]);
292
		}
320
		}
293
321
294
		if (zlib_err != Z_STREAM_END)
322
		sbuf[Src].buf = percpu->read_data;
295
			goto release_mutex;
323
		sbuf[Src].sz = bytes;
296
324
		sbuf[Dst].buf = buffer;
297
		zlib_err = zlib_inflateEnd(&msblk->stream);
325
		sbuf[Dst].sz = srclength;
298
		if (zlib_err != Z_OK) {
326
		dpri_un(&percpu->un);
299
			ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
327
		dpri("src %d %p, dst %d %p\n", sbuf[Src].sz, sbuf[Src].buf,
300
				" srclength %d\n", zlib_err, srclength);
328
		     sbuf[Dst].sz, sbuf[Dst].buf);
329
		zlib_err = sqlzma_un(&percpu->un, sbuf + Src, sbuf + Dst);
330
		bytes = percpu->un.un_reslen;
331
332
#ifdef KeepPreemptive
333
		mutex_unlock(&percpu->mtx);
334
#else
335
		put_cpu_var(sqlzma);
336
#endif
337
		if (unlikely(zlib_err)) {
338
			dpri("zlib_err %d\n", zlib_err);
301
			goto release_mutex;
339
			goto release_mutex;
302
		}
340
		}
303
		bytes = msblk->stream.total_out;
341
		/* mutex_unlock(&msblk->read_data_mutex); */
304
		mutex_unlock(&msblk->read_data_mutex);
305
	} else {
342
	} else {
306
		int i;
343
		int i;
307
344
Lines 329-335 Link Here
329
	return bytes;
366
	return bytes;
330
367
331
release_mutex:
368
release_mutex:
332
	mutex_unlock(&msblk->read_data_mutex);
369
	/* mutex_unlock(&msblk->read_data_mutex); */
333
370
334
block_release:
371
block_release:
335
	for (; k < b; k++)
372
	for (; k < b; k++)
Lines 1083-1094 Link Here
1083
{
1120
{
1084
	struct squashfs_sb_info *msblk;
1121
	struct squashfs_sb_info *msblk;
1085
	struct squashfs_super_block *sblk;
1122
	struct squashfs_super_block *sblk;
1086
	int i;
1123
	int i, err;
1087
	char b[BDEVNAME_SIZE];
1124
	char b[BDEVNAME_SIZE];
1088
	struct inode *root;
1125
	struct inode *root;
1089
1126
1090
	TRACE("Entered squashfs_fill_superblock\n");
1127
	TRACE("Entered squashfs_fill_superblock\n");
1091
1128
1129
	err = -ENOMEM;
1092
	s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1130
	s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1093
	if (s->s_fs_info == NULL) {
1131
	if (s->s_fs_info == NULL) {
1094
		ERROR("Failed to allocate superblock\n");
1132
		ERROR("Failed to allocate superblock\n");
Lines 1096-1112 Link Here
1096
	}
1134
	}
1097
	msblk = s->s_fs_info;
1135
	msblk = s->s_fs_info;
1098
1136
1099
	msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1100
	if (msblk->stream.workspace == NULL) {
1101
		ERROR("Failed to allocate zlib workspace\n");
1102
		goto failure;
1103
	}
1104
	sblk = &msblk->sblk;
1137
	sblk = &msblk->sblk;
1105
	
1138
	
1106
	msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1139
	msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1107
	msblk->devblksize_log2 = ffz(~msblk->devblksize);
1140
	msblk->devblksize_log2 = ffz(~msblk->devblksize);
1108
1141
1109
	mutex_init(&msblk->read_data_mutex);
1142
	/* mutex_init(&msblk->read_data_mutex); */
1110
	mutex_init(&msblk->read_page_mutex);
1143
	mutex_init(&msblk->read_page_mutex);
1111
	mutex_init(&msblk->block_cache_mutex);
1144
	mutex_init(&msblk->block_cache_mutex);
1112
	mutex_init(&msblk->fragment_mutex);
1145
	mutex_init(&msblk->fragment_mutex);
Lines 1118-1123 Link Here
1118
	/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1151
	/* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1119
 	 * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,
1152
 	 * beyond filesystem end.  As we're using squashfs_read_data to read sblk here,
1120
 	 * first set sblk->bytes_used to a useful value */
1153
 	 * first set sblk->bytes_used to a useful value */
1154
	err = -EINVAL;
1121
	sblk->bytes_used = sizeof(struct squashfs_super_block);
1155
	sblk->bytes_used = sizeof(struct squashfs_super_block);
1122
	if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1156
	if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1123
					sizeof(struct squashfs_super_block) |
1157
					sizeof(struct squashfs_super_block) |
Lines 1127-1147 Link Here
1127
	}
1161
	}
1128
1162
1129
	/* Check it is a SQUASHFS superblock */
1163
	/* Check it is a SQUASHFS superblock */
1130
	if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1164
	s->s_magic = sblk->s_magic;
1131
		if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1165
	msblk->swap = 0;
1132
			struct squashfs_super_block ssblk;
1166
	dpri("magic 0x%x\n", sblk->s_magic);
1133
1167
	switch (sblk->s_magic) {
1134
			WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1168
		struct squashfs_super_block ssblk;
1135
				bdevname(s->s_bdev, b));
1169
1136
1170
	case SQUASHFS_MAGIC_SWAP:
1137
			SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1171
		/*FALLTHROUGH*/
1138
			memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1172
	case SQUASHFS_MAGIC_LZMA_SWAP:
1139
			msblk->swap = 1;
1173
		WARNING("Mounting a different endian SQUASHFS "
1140
		} else  {
1174
			"filesystem on %s\n", bdevname(s->s_bdev, b));
1141
			SERROR("Can't find a SQUASHFS superblock on %s\n",
1175
1142
							bdevname(s->s_bdev, b));
1176
		SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1143
			goto failed_mount;
1177
		memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1144
		}
1178
		msblk->swap = 1;
1179
		/*FALLTHROUGH*/
1180
	case SQUASHFS_MAGIC:
1181
	case SQUASHFS_MAGIC_LZMA:
1182
		break;
1183
	default:
1184
		SERROR("Can't find a SQUASHFS superblock on %s\n",
1185
		       bdevname(s->s_bdev, b));
1186
		goto failed_mount;
1187
	}
1188
1189
	{
1190
		struct sqlzma *p;
1191
		dpri("block_size %d, devblksize %d\n",
1192
		     sblk->block_size, msblk->devblksize);
1193
		BUG_ON(sblk->block_size > sizeof(p->read_data));
1145
	}
1194
	}
1146
1195
1147
	/* Check the MAJOR & MINOR versions */
1196
	/* Check the MAJOR & MINOR versions */
Lines 1185-1190 Link Here
1185
		goto failed_mount;
1234
		goto failed_mount;
1186
1235
1187
	/* Allocate read_page block */
1236
	/* Allocate read_page block */
1237
	err = -ENOMEM;
1188
	msblk->read_page = vmalloc(sblk->block_size);
1238
	msblk->read_page = vmalloc(sblk->block_size);
1189
	if (msblk->read_page == NULL) {
1239
	if (msblk->read_page == NULL) {
1190
		ERROR("Failed to allocate read_page block\n");
1240
		ERROR("Failed to allocate read_page block\n");
Lines 1200-1218 Link Here
1200
	}
1250
	}
1201
	msblk->guid = msblk->uid + sblk->no_uids;
1251
	msblk->guid = msblk->uid + sblk->no_uids;
1202
   
1252
   
1253
	dpri("swap %d\n", msblk->swap);
1254
	err = -EINVAL;
1203
	if (msblk->swap) {
1255
	if (msblk->swap) {
1204
		unsigned int suid[sblk->no_uids + sblk->no_guids];
1256
		unsigned int *suid;
1257
1258
		err = -ENOMEM;
1259
		suid = kmalloc(sizeof(*suid) * (sblk->no_uids + sblk->no_guids),
1260
			       GFP_KERNEL);
1261
		if (unlikely(!suid))
1262
			goto failed_mount;
1205
1263
1264
		err = -EINVAL;
1206
		if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1265
		if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1207
					((sblk->no_uids + sblk->no_guids) *
1266
					((sblk->no_uids + sblk->no_guids) *
1208
					 sizeof(unsigned int)) |
1267
					 sizeof(unsigned int)) |
1209
					SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1268
					SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1210
			ERROR("unable to read uid/gid table\n");
1269
			ERROR("unable to read uid/gid table\n");
1270
			kfree(suid);
1211
			goto failed_mount;
1271
			goto failed_mount;
1212
		}
1272
		}
1213
1273
1214
		SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1274
		SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1215
			sblk->no_guids), (sizeof(unsigned int) * 8));
1275
			sblk->no_guids), (sizeof(unsigned int) * 8));
1276
		kfree(suid);
1216
	} else
1277
	} else
1217
		if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1278
		if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1218
					((sblk->no_uids + sblk->no_guids) *
1279
					((sblk->no_uids + sblk->no_guids) *
Lines 1226-1231 Link Here
1226
	if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1287
	if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1227
		goto allocate_root;
1288
		goto allocate_root;
1228
1289
1290
	err = -ENOMEM;
1229
	msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *
1291
	msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *
1230
				SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);
1292
				SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);
1231
	if (msblk->fragment == NULL) {
1293
	if (msblk->fragment == NULL) {
Lines 1255-1263 Link Here
1255
	s->s_export_op = &squashfs_export_ops;
1317
	s->s_export_op = &squashfs_export_ops;
1256
1318
1257
allocate_root:
1319
allocate_root:
1320
	dpri("alloate_root\n");
1258
	root = new_inode(s);
1321
	root = new_inode(s);
1259
	if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1322
	if ((msblk->read_inode)(root, sblk->root_inode) == 0) {
1323
		iput(root);
1260
		goto failed_mount;
1324
		goto failed_mount;
1325
	}
1261
	insert_inode_hash(root);
1326
	insert_inode_hash(root);
1262
1327
1263
	s->s_root = d_alloc_root(root);
1328
	s->s_root = d_alloc_root(root);
Lines 1278-1290 Link Here
1278
	vfree(msblk->read_page);
1343
	vfree(msblk->read_page);
1279
	kfree(msblk->block_cache);
1344
	kfree(msblk->block_cache);
1280
	kfree(msblk->fragment_index_2);
1345
	kfree(msblk->fragment_index_2);
1281
	vfree(msblk->stream.workspace);
1282
	kfree(s->s_fs_info);
1346
	kfree(s->s_fs_info);
1283
	s->s_fs_info = NULL;
1347
	s->s_fs_info = NULL;
1284
	return -EINVAL;
1348
 failure:
1285
1349
	return err;
1286
failure:
1287
	return -ENOMEM;
1288
}
1350
}
1289
1351
1290
1352
Lines 1295-1301 Link Here
1295
1357
1296
	TRACE("Entered squashfs_statfs\n");
1358
	TRACE("Entered squashfs_statfs\n");
1297
1359
1298
	buf->f_type = SQUASHFS_MAGIC;
1360
	buf->f_type = sblk->s_magic;
1299
	buf->f_bsize = sblk->block_size;
1361
	buf->f_bsize = sblk->block_size;
1300
	buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1362
	buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1301
	buf->f_bfree = buf->f_bavail = 0;
1363
	buf->f_bfree = buf->f_bavail = 0;
Lines 1457-1471 Link Here
1457
	int block = 0;
1519
	int block = 0;
1458
	
1520
	
1459
	if (msblk->swap) {
1521
	if (msblk->swap) {
1460
		char sblock_list[blocks << 2];
1522
		char *sblock_list;
1523
1524
		sblock_list = kmalloc(blocks << 2, GFP_KERNEL);
1525
		if (unlikely(!sblock_list))
1526
			goto failure;
1461
1527
1462
		if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1528
		if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1463
				*offset, blocks << 2, start_block, offset)) {
1529
				*offset, blocks << 2, start_block, offset)) {
1464
			ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1530
			ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1531
			kfree(sblock_list);
1465
			goto failure;
1532
			goto failure;
1466
		}
1533
		}
1467
		SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1534
		SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1468
				((unsigned int *)sblock_list), blocks);
1535
				((unsigned int *)sblock_list), blocks);
1536
		kfree(sblock_list);
1469
	} else {
1537
	} else {
1470
		if (!squashfs_get_cached_block(s, block_list, *start_block,
1538
		if (!squashfs_get_cached_block(s, block_list, *start_block,
1471
				*offset, blocks << 2, start_block, offset)) {
1539
				*offset, blocks << 2, start_block, offset)) {
Lines 2097-2103 Link Here
2097
		kfree(sbi->fragment_index);
2165
		kfree(sbi->fragment_index);
2098
		kfree(sbi->fragment_index_2);
2166
		kfree(sbi->fragment_index_2);
2099
		kfree(sbi->meta_index);
2167
		kfree(sbi->meta_index);
2100
		vfree(sbi->stream.workspace);
2101
		kfree(s->s_fs_info);
2168
		kfree(s->s_fs_info);
2102
		s->s_fs_info = NULL;
2169
		s->s_fs_info = NULL;
2103
	}
2170
	}
Lines 2111-2129 Link Here
2111
				mnt);
2178
				mnt);
2112
}
2179
}
2113
2180
2181
static void free_sqlzma(void)
2182
{
2183
	int cpu;
2184
	struct sqlzma *p;
2185
2186
	for_each_online_cpu(cpu) {
2187
		p = per_cpu(sqlzma, cpu);
2188
		if (p) {
2189
#ifdef KeepPreemptive
2190
			mutex_destroy(&p->mtx);
2191
#endif
2192
			sqlzma_fin(&p->un);
2193
			kfree(p);
2194
		}
2195
	}
2196
}
2114
2197
2115
static int __init init_squashfs_fs(void)
2198
static int __init init_squashfs_fs(void)
2116
{
2199
{
2200
	struct sqlzma *p;
2201
	int cpu;
2117
	int err = init_inodecache();
2202
	int err = init_inodecache();
2118
	if (err)
2203
	if (err)
2119
		goto out;
2204
		goto out;
2120
2205
2206
	for_each_online_cpu(cpu) {
2207
		dpri("%d: %p\n", cpu, per_cpu(sqlzma, cpu));
2208
		err = -ENOMEM;
2209
		p = kmalloc(sizeof(struct sqlzma), GFP_KERNEL);
2210
		if (p) {
2211
#ifdef KeepPreemptive
2212
			mutex_init(&p->mtx);
2213
#endif
2214
			err = sqlzma_init(&p->un, 1, 0);
2215
			if (unlikely(err)) {
2216
				ERROR("Failed to intialize uncompress workspace\n");
2217
				break;
2218
			}
2219
			per_cpu(sqlzma, cpu) = p;
2220
			err = 0;
2221
		} else
2222
			break;
2223
	}
2224
	if (unlikely(err)) {
2225
		free_sqlzma();
2226
		goto out;
2227
	}
2228
2121
	printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) "
2229
	printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) "
2122
		"Phillip Lougher\n");
2230
		"Phillip Lougher\n"
2231
		"squashfs: LZMA suppport for slax.org by jro\n");
2123
2232
2124
	err = register_filesystem(&squashfs_fs_type);
2233
	err = register_filesystem(&squashfs_fs_type);
2125
	if (err)
2234
	if (err) {
2235
		free_sqlzma();
2126
		destroy_inodecache();
2236
		destroy_inodecache();
2237
	}
2127
2238
2128
out:
2239
out:
2129
	return err;
2240
	return err;
Lines 2133-2138 Link Here
2133
static void __exit exit_squashfs_fs(void)
2244
static void __exit exit_squashfs_fs(void)
2134
{
2245
{
2135
	unregister_filesystem(&squashfs_fs_type);
2246
	unregister_filesystem(&squashfs_fs_type);
2247
	free_sqlzma();
2136
	destroy_inodecache();
2248
	destroy_inodecache();
2137
}
2249
}
2138
2250
Lines 2181-2186 Link Here
2181
2293
2182
module_init(init_squashfs_fs);
2294
module_init(init_squashfs_fs);
2183
module_exit(exit_squashfs_fs);
2295
module_exit(exit_squashfs_fs);
2184
MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem");
2296
MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem, and LZMA suppport for slax.org");
2185
MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2297
MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>, and LZMA suppport for slax.org by jro");
2186
MODULE_LICENSE("GPL");
2298
MODULE_LICENSE("GPL");
(-)linux-2.6.25-gentoo-r8.orig/fs/squashfs/Makefile (+5 lines)
Lines 2-7 Link Here
2
# Makefile for the linux squashfs routines.
2
# Makefile for the linux squashfs routines.
3
#
3
#
4
4
5
# the environment variables are not inherited since 2.6.23
6
ifdef SQLZMA_EXTRA_CFLAGS
7
EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}
8
endif
9
5
obj-$(CONFIG_SQUASHFS) += squashfs.o
10
obj-$(CONFIG_SQUASHFS) += squashfs.o
6
squashfs-y += inode.o
11
squashfs-y += inode.o
7
squashfs-y += squashfs2_0.o
12
squashfs-y += squashfs2_0.o
(-)linux-2.6.25-gentoo-r8.orig/fs/squashfs/sqmagic.h (+17 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2006 Junjiro Okajima
3
 * Copyright (C) 2006 Tomas Matejicek, slax.org
4
 *
5
 * LICENSE must follow the one in squashfs.
6
 */
7
8
/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */
9
10
#ifndef __sqmagic_h__
11
#define __sqmagic_h__
12
13
/* see SQUASHFS_MAGIC in squashfs_fs.h */
14
#define SQUASHFS_MAGIC_LZMA		0x71736873
15
#define SQUASHFS_MAGIC_LZMA_SWAP	0x73687371
16
17
#endif
(-)linux-2.6.25-gentoo-r8.orig/include/linux/squashfs_fs.h (-1 / +1 lines)
Lines 341-347 Link Here
341
	unsigned int		offset:13;
341
	unsigned int		offset:13;
342
	unsigned int		type:3;
342
	unsigned int		type:3;
343
	unsigned int		size:8;
343
	unsigned int		size:8;
344
	int			inode_number:16;
344
	signed int		inode_number:16; /* very important signedness */
345
	char			name[0];
345
	char			name[0];
346
} __attribute__ ((packed));
346
} __attribute__ ((packed));
347
347
(-)linux-2.6.25-gentoo-r8.orig/include/linux/squashfs_fs_sb.h (-2 / +2 lines)
Lines 54-60 Link Here
54
	long long		*fragment_index;
54
	long long		*fragment_index;
55
	unsigned int		*fragment_index_2;
55
	unsigned int		*fragment_index_2;
56
	char			*read_page;
56
	char			*read_page;
57
	struct mutex		read_data_mutex;
57
	/* struct mutex		read_data_mutex; */
58
	struct mutex		read_page_mutex;
58
	struct mutex		read_page_mutex;
59
	struct mutex		block_cache_mutex;
59
	struct mutex		block_cache_mutex;
60
	struct mutex		fragment_mutex;
60
	struct mutex		fragment_mutex;
Lines 62-68 Link Here
62
	wait_queue_head_t	waitq;
62
	wait_queue_head_t	waitq;
63
	wait_queue_head_t	fragment_wait_queue;
63
	wait_queue_head_t	fragment_wait_queue;
64
	struct meta_index	*meta_index;
64
	struct meta_index	*meta_index;
65
	z_stream		stream;
65
	/* z_stream		stream; */
66
	long long		*inode_lookup_table;
66
	long long		*inode_lookup_table;
67
	int			unused_cache_blks;
67
	int			unused_cache_blks;
68
	int			unused_frag_blks;
68
	int			unused_frag_blks;
(-)linux-2.6.25-gentoo-r8.orig/lib/Kconfig (+3 lines)
Lines 77-82 Link Here
77
77
78
config LZO_DECOMPRESS
78
config LZO_DECOMPRESS
79
	tristate
79
	tristate
80
	  
81
config LZMA
82
	tristate
80
83
81
#
84
#
82
# Generic allocator support is selected if needed
85
# Generic allocator support is selected if needed
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/LzmaDecode.c (+584 lines)
Line 0 Link Here
1
/*
2
  LzmaDecode.c
3
  LZMA Decoder (optimized for Speed version)
4
  
5
  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
6
  http://www.7-zip.org/
7
8
  LZMA SDK is licensed under two licenses:
9
  1) GNU Lesser General Public License (GNU LGPL)
10
  2) Common Public License (CPL)
11
  It means that you can select one of these two licenses and 
12
  follow rules of that license.
13
14
  SPECIAL EXCEPTION:
15
  Igor Pavlov, as the author of this Code, expressly permits you to 
16
  statically or dynamically link your Code (or bind by name) to the 
17
  interfaces of this file without subjecting your linked Code to the 
18
  terms of the CPL or GNU LGPL. Any modifications or additions 
19
  to this file, however, are subject to the LGPL or CPL terms.
20
*/
21
22
#include "LzmaDecode.h"
23
24
#define kNumTopBits 24
25
#define kTopValue ((UInt32)1 << kNumTopBits)
26
27
#define kNumBitModelTotalBits 11
28
#define kBitModelTotal (1 << kNumBitModelTotalBits)
29
#define kNumMoveBits 5
30
31
#define RC_READ_BYTE (*Buffer++)
32
33
#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
34
  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
35
36
#ifdef _LZMA_IN_CB
37
38
#define RC_TEST { if (Buffer == BufferLim) \
39
  { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
40
  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
41
42
#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
43
44
#else
45
46
#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
47
48
#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
49
 
50
#endif
51
52
#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
53
54
#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
55
#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
56
#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
57
58
#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
59
  { UpdateBit0(p); mi <<= 1; A0; } else \
60
  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 
61
  
62
#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               
63
64
#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
65
  { int i = numLevels; res = 1; \
66
  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
67
  res -= (1 << numLevels); }
68
69
70
#define kNumPosBitsMax 4
71
#define kNumPosStatesMax (1 << kNumPosBitsMax)
72
73
#define kLenNumLowBits 3
74
#define kLenNumLowSymbols (1 << kLenNumLowBits)
75
#define kLenNumMidBits 3
76
#define kLenNumMidSymbols (1 << kLenNumMidBits)
77
#define kLenNumHighBits 8
78
#define kLenNumHighSymbols (1 << kLenNumHighBits)
79
80
#define LenChoice 0
81
#define LenChoice2 (LenChoice + 1)
82
#define LenLow (LenChoice2 + 1)
83
#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
84
#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
85
#define kNumLenProbs (LenHigh + kLenNumHighSymbols) 
86
87
88
#define kNumStates 12
89
#define kNumLitStates 7
90
91
#define kStartPosModelIndex 4
92
#define kEndPosModelIndex 14
93
#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
94
95
#define kNumPosSlotBits 6
96
#define kNumLenToPosStates 4
97
98
#define kNumAlignBits 4
99
#define kAlignTableSize (1 << kNumAlignBits)
100
101
#define kMatchMinLen 2
102
103
#define IsMatch 0
104
#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
105
#define IsRepG0 (IsRep + kNumStates)
106
#define IsRepG1 (IsRepG0 + kNumStates)
107
#define IsRepG2 (IsRepG1 + kNumStates)
108
#define IsRep0Long (IsRepG2 + kNumStates)
109
#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
110
#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
111
#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
112
#define LenCoder (Align + kAlignTableSize)
113
#define RepLenCoder (LenCoder + kNumLenProbs)
114
#define Literal (RepLenCoder + kNumLenProbs)
115
116
#if Literal != LZMA_BASE_SIZE
117
StopCompilingDueBUG
118
#endif
119
120
int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
121
{
122
  unsigned char prop0;
123
  if (size < LZMA_PROPERTIES_SIZE)
124
    return LZMA_RESULT_DATA_ERROR;
125
  prop0 = propsData[0];
126
  if (prop0 >= (9 * 5 * 5))
127
    return LZMA_RESULT_DATA_ERROR;
128
  {
129
    for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
130
    for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
131
    propsRes->lc = prop0;
132
    /*
133
    unsigned char remainder = (unsigned char)(prop0 / 9);
134
    propsRes->lc = prop0 % 9;
135
    propsRes->pb = remainder / 5;
136
    propsRes->lp = remainder % 5;
137
    */
138
  }
139
140
  #ifdef _LZMA_OUT_READ
141
  {
142
    int i;
143
    propsRes->DictionarySize = 0;
144
    for (i = 0; i < 4; i++)
145
      propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
146
    if (propsRes->DictionarySize == 0)
147
      propsRes->DictionarySize = 1;
148
  }
149
  #endif
150
  return LZMA_RESULT_OK;
151
}
152
153
#define kLzmaStreamWasFinishedId (-1)
154
155
int LzmaDecode(CLzmaDecoderState *vs,
156
    #ifdef _LZMA_IN_CB
157
    ILzmaInCallback *InCallback,
158
    #else
159
    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
160
    #endif
161
    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
162
{
163
  CProb *p = vs->Probs;
164
  SizeT nowPos = 0;
165
  Byte previousByte = 0;
166
  UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
167
  UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
168
  int lc = vs->Properties.lc;
169
170
  #ifdef _LZMA_OUT_READ
171
  
172
  UInt32 Range = vs->Range;
173
  UInt32 Code = vs->Code;
174
  #ifdef _LZMA_IN_CB
175
  const Byte *Buffer = vs->Buffer;
176
  const Byte *BufferLim = vs->BufferLim;
177
  #else
178
  const Byte *Buffer = inStream;
179
  const Byte *BufferLim = inStream + inSize;
180
  #endif
181
  int state = vs->State;
182
  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
183
  int len = vs->RemainLen;
184
  UInt32 globalPos = vs->GlobalPos;
185
  UInt32 distanceLimit = vs->DistanceLimit;
186
187
  Byte *dictionary = vs->Dictionary;
188
  UInt32 dictionarySize = vs->Properties.DictionarySize;
189
  UInt32 dictionaryPos = vs->DictionaryPos;
190
191
  Byte tempDictionary[4];
192
193
  #ifndef _LZMA_IN_CB
194
  *inSizeProcessed = 0;
195
  #endif
196
  *outSizeProcessed = 0;
197
  if (len == kLzmaStreamWasFinishedId)
198
    return LZMA_RESULT_OK;
199
200
  if (dictionarySize == 0)
201
  {
202
    dictionary = tempDictionary;
203
    dictionarySize = 1;
204
    tempDictionary[0] = vs->TempDictionary[0];
205
  }
206
207
  if (len == kLzmaNeedInitId)
208
  {
209
    {
210
      UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
211
      UInt32 i;
212
      for (i = 0; i < numProbs; i++)
213
        p[i] = kBitModelTotal >> 1; 
214
      rep0 = rep1 = rep2 = rep3 = 1;
215
      state = 0;
216
      globalPos = 0;
217
      distanceLimit = 0;
218
      dictionaryPos = 0;
219
      dictionary[dictionarySize - 1] = 0;
220
      #ifdef _LZMA_IN_CB
221
      RC_INIT;
222
      #else
223
      RC_INIT(inStream, inSize);
224
      #endif
225
    }
226
    len = 0;
227
  }
228
  while(len != 0 && nowPos < outSize)
229
  {
230
    UInt32 pos = dictionaryPos - rep0;
231
    if (pos >= dictionarySize)
232
      pos += dictionarySize;
233
    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
234
    if (++dictionaryPos == dictionarySize)
235
      dictionaryPos = 0;
236
    len--;
237
  }
238
  if (dictionaryPos == 0)
239
    previousByte = dictionary[dictionarySize - 1];
240
  else
241
    previousByte = dictionary[dictionaryPos - 1];
242
243
  #else /* if !_LZMA_OUT_READ */
244
245
  int state = 0;
246
  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
247
  int len = 0;
248
  const Byte *Buffer;
249
  const Byte *BufferLim;
250
  UInt32 Range;
251
  UInt32 Code;
252
253
  #ifndef _LZMA_IN_CB
254
  *inSizeProcessed = 0;
255
  #endif
256
  *outSizeProcessed = 0;
257
258
  {
259
    UInt32 i;
260
    UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
261
    for (i = 0; i < numProbs; i++)
262
      p[i] = kBitModelTotal >> 1;
263
  }
264
  
265
  #ifdef _LZMA_IN_CB
266
  RC_INIT;
267
  #else
268
  RC_INIT(inStream, inSize);
269
  #endif
270
271
  #endif /* _LZMA_OUT_READ */
272
273
  while(nowPos < outSize)
274
  {
275
    CProb *prob;
276
    UInt32 bound;
277
    int posState = (int)(
278
        (nowPos 
279
        #ifdef _LZMA_OUT_READ
280
        + globalPos
281
        #endif
282
        )
283
        & posStateMask);
284
285
    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
286
    IfBit0(prob)
287
    {
288
      int symbol = 1;
289
      UpdateBit0(prob)
290
      prob = p + Literal + (LZMA_LIT_SIZE * 
291
        (((
292
        (nowPos 
293
        #ifdef _LZMA_OUT_READ
294
        + globalPos
295
        #endif
296
        )
297
        & literalPosMask) << lc) + (previousByte >> (8 - lc))));
298
299
      if (state >= kNumLitStates)
300
      {
301
        int matchByte;
302
        #ifdef _LZMA_OUT_READ
303
        UInt32 pos = dictionaryPos - rep0;
304
        if (pos >= dictionarySize)
305
          pos += dictionarySize;
306
        matchByte = dictionary[pos];
307
        #else
308
        matchByte = outStream[nowPos - rep0];
309
        #endif
310
        do
311
        {
312
          int bit;
313
          CProb *probLit;
314
          matchByte <<= 1;
315
          bit = (matchByte & 0x100);
316
          probLit = prob + 0x100 + bit + symbol;
317
          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
318
        }
319
        while (symbol < 0x100);
320
      }
321
      while (symbol < 0x100)
322
      {
323
        CProb *probLit = prob + symbol;
324
        RC_GET_BIT(probLit, symbol)
325
      }
326
      previousByte = (Byte)symbol;
327
328
      outStream[nowPos++] = previousByte;
329
      #ifdef _LZMA_OUT_READ
330
      if (distanceLimit < dictionarySize)
331
        distanceLimit++;
332
333
      dictionary[dictionaryPos] = previousByte;
334
      if (++dictionaryPos == dictionarySize)
335
        dictionaryPos = 0;
336
      #endif
337
      if (state < 4) state = 0;
338
      else if (state < 10) state -= 3;
339
      else state -= 6;
340
    }
341
    else             
342
    {
343
      UpdateBit1(prob);
344
      prob = p + IsRep + state;
345
      IfBit0(prob)
346
      {
347
        UpdateBit0(prob);
348
        rep3 = rep2;
349
        rep2 = rep1;
350
        rep1 = rep0;
351
        state = state < kNumLitStates ? 0 : 3;
352
        prob = p + LenCoder;
353
      }
354
      else
355
      {
356
        UpdateBit1(prob);
357
        prob = p + IsRepG0 + state;
358
        IfBit0(prob)
359
        {
360
          UpdateBit0(prob);
361
          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
362
          IfBit0(prob)
363
          {
364
            #ifdef _LZMA_OUT_READ
365
            UInt32 pos;
366
            #endif
367
            UpdateBit0(prob);
368
            
369
            #ifdef _LZMA_OUT_READ
370
            if (distanceLimit == 0)
371
            #else
372
            if (nowPos == 0)
373
            #endif
374
              return LZMA_RESULT_DATA_ERROR;
375
            
376
            state = state < kNumLitStates ? 9 : 11;
377
            #ifdef _LZMA_OUT_READ
378
            pos = dictionaryPos - rep0;
379
            if (pos >= dictionarySize)
380
              pos += dictionarySize;
381
            previousByte = dictionary[pos];
382
            dictionary[dictionaryPos] = previousByte;
383
            if (++dictionaryPos == dictionarySize)
384
              dictionaryPos = 0;
385
            #else
386
            previousByte = outStream[nowPos - rep0];
387
            #endif
388
            outStream[nowPos++] = previousByte;
389
            #ifdef _LZMA_OUT_READ
390
            if (distanceLimit < dictionarySize)
391
              distanceLimit++;
392
            #endif
393
394
            continue;
395
          }
396
          else
397
          {
398
            UpdateBit1(prob);
399
          }
400
        }
401
        else
402
        {
403
          UInt32 distance;
404
          UpdateBit1(prob);
405
          prob = p + IsRepG1 + state;
406
          IfBit0(prob)
407
          {
408
            UpdateBit0(prob);
409
            distance = rep1;
410
          }
411
          else 
412
          {
413
            UpdateBit1(prob);
414
            prob = p + IsRepG2 + state;
415
            IfBit0(prob)
416
            {
417
              UpdateBit0(prob);
418
              distance = rep2;
419
            }
420
            else
421
            {
422
              UpdateBit1(prob);
423
              distance = rep3;
424
              rep3 = rep2;
425
            }
426
            rep2 = rep1;
427
          }
428
          rep1 = rep0;
429
          rep0 = distance;
430
        }
431
        state = state < kNumLitStates ? 8 : 11;
432
        prob = p + RepLenCoder;
433
      }
434
      {
435
        int numBits, offset;
436
        CProb *probLen = prob + LenChoice;
437
        IfBit0(probLen)
438
        {
439
          UpdateBit0(probLen);
440
          probLen = prob + LenLow + (posState << kLenNumLowBits);
441
          offset = 0;
442
          numBits = kLenNumLowBits;
443
        }
444
        else
445
        {
446
          UpdateBit1(probLen);
447
          probLen = prob + LenChoice2;
448
          IfBit0(probLen)
449
          {
450
            UpdateBit0(probLen);
451
            probLen = prob + LenMid + (posState << kLenNumMidBits);
452
            offset = kLenNumLowSymbols;
453
            numBits = kLenNumMidBits;
454
          }
455
          else
456
          {
457
            UpdateBit1(probLen);
458
            probLen = prob + LenHigh;
459
            offset = kLenNumLowSymbols + kLenNumMidSymbols;
460
            numBits = kLenNumHighBits;
461
          }
462
        }
463
        RangeDecoderBitTreeDecode(probLen, numBits, len);
464
        len += offset;
465
      }
466
467
      if (state < 4)
468
      {
469
        int posSlot;
470
        state += kNumLitStates;
471
        prob = p + PosSlot +
472
            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << 
473
            kNumPosSlotBits);
474
        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
475
        if (posSlot >= kStartPosModelIndex)
476
        {
477
          int numDirectBits = ((posSlot >> 1) - 1);
478
          rep0 = (2 | ((UInt32)posSlot & 1));
479
          if (posSlot < kEndPosModelIndex)
480
          {
481
            rep0 <<= numDirectBits;
482
            prob = p + SpecPos + rep0 - posSlot - 1;
483
          }
484
          else
485
          {
486
            numDirectBits -= kNumAlignBits;
487
            do
488
            {
489
              RC_NORMALIZE
490
              Range >>= 1;
491
              rep0 <<= 1;
492
              if (Code >= Range)
493
              {
494
                Code -= Range;
495
                rep0 |= 1;
496
              }
497
            }
498
            while (--numDirectBits != 0);
499
            prob = p + Align;
500
            rep0 <<= kNumAlignBits;
501
            numDirectBits = kNumAlignBits;
502
          }
503
          {
504
            int i = 1;
505
            int mi = 1;
506
            do
507
            {
508
              CProb *prob3 = prob + mi;
509
              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
510
              i <<= 1;
511
            }
512
            while(--numDirectBits != 0);
513
          }
514
        }
515
        else
516
          rep0 = posSlot;
517
        if (++rep0 == (UInt32)(0))
518
        {
519
          /* it's for stream version */
520
          len = kLzmaStreamWasFinishedId;
521
          break;
522
        }
523
      }
524
525
      len += kMatchMinLen;
526
      #ifdef _LZMA_OUT_READ
527
      if (rep0 > distanceLimit) 
528
      #else
529
      if (rep0 > nowPos)
530
      #endif
531
        return LZMA_RESULT_DATA_ERROR;
532
533
      #ifdef _LZMA_OUT_READ
534
      if (dictionarySize - distanceLimit > (UInt32)len)
535
        distanceLimit += len;
536
      else
537
        distanceLimit = dictionarySize;
538
      #endif
539
540
      do
541
      {
542
        #ifdef _LZMA_OUT_READ
543
        UInt32 pos = dictionaryPos - rep0;
544
        if (pos >= dictionarySize)
545
          pos += dictionarySize;
546
        previousByte = dictionary[pos];
547
        dictionary[dictionaryPos] = previousByte;
548
        if (++dictionaryPos == dictionarySize)
549
          dictionaryPos = 0;
550
        #else
551
        previousByte = outStream[nowPos - rep0];
552
        #endif
553
        len--;
554
        outStream[nowPos++] = previousByte;
555
      }
556
      while(len != 0 && nowPos < outSize);
557
    }
558
  }
559
  RC_NORMALIZE;
560
561
  #ifdef _LZMA_OUT_READ
562
  vs->Range = Range;
563
  vs->Code = Code;
564
  vs->DictionaryPos = dictionaryPos;
565
  vs->GlobalPos = globalPos + (UInt32)nowPos;
566
  vs->DistanceLimit = distanceLimit;
567
  vs->Reps[0] = rep0;
568
  vs->Reps[1] = rep1;
569
  vs->Reps[2] = rep2;
570
  vs->Reps[3] = rep3;
571
  vs->State = state;
572
  vs->RemainLen = len;
573
  vs->TempDictionary[0] = tempDictionary[0];
574
  #endif
575
576
  #ifdef _LZMA_IN_CB
577
  vs->Buffer = Buffer;
578
  vs->BufferLim = BufferLim;
579
  #else
580
  *inSizeProcessed = (SizeT)(Buffer - inStream);
581
  #endif
582
  *outSizeProcessed = nowPos;
583
  return LZMA_RESULT_OK;
584
}
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/LzmaDecode.h (+113 lines)
Line 0 Link Here
1
/* 
2
  LzmaDecode.h
3
  LZMA Decoder interface
4
5
  LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
6
  http://www.7-zip.org/
7
8
  LZMA SDK is licensed under two licenses:
9
  1) GNU Lesser General Public License (GNU LGPL)
10
  2) Common Public License (CPL)
11
  It means that you can select one of these two licenses and 
12
  follow rules of that license.
13
14
  SPECIAL EXCEPTION:
15
  Igor Pavlov, as the author of this code, expressly permits you to 
16
  statically or dynamically link your code (or bind by name) to the 
17
  interfaces of this file without subjecting your linked code to the 
18
  terms of the CPL or GNU LGPL. Any modifications or additions 
19
  to this file, however, are subject to the LGPL or CPL terms.
20
*/
21
22
#ifndef __LZMADECODE_H
23
#define __LZMADECODE_H
24
25
#include "LzmaTypes.h"
26
27
/* #define _LZMA_IN_CB */
28
/* Use callback for input data */
29
30
/* #define _LZMA_OUT_READ */
31
/* Use read function for output data */
32
33
/* #define _LZMA_PROB32 */
34
/* It can increase speed on some 32-bit CPUs, 
35
   but memory usage will be doubled in that case */
36
37
/* #define _LZMA_LOC_OPT */
38
/* Enable local speed optimizations inside code */
39
40
#ifdef _LZMA_PROB32
41
#define CProb UInt32
42
#else
43
#define CProb UInt16
44
#endif
45
46
#define LZMA_RESULT_OK 0
47
#define LZMA_RESULT_DATA_ERROR 1
48
49
#ifdef _LZMA_IN_CB
50
typedef struct _ILzmaInCallback
51
{
52
  int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
53
} ILzmaInCallback;
54
#endif
55
56
#define LZMA_BASE_SIZE 1846
57
#define LZMA_LIT_SIZE 768
58
59
#define LZMA_PROPERTIES_SIZE 5
60
61
typedef struct _CLzmaProperties
62
{
63
  int lc;
64
  int lp;
65
  int pb;
66
  #ifdef _LZMA_OUT_READ
67
  UInt32 DictionarySize;
68
  #endif
69
}CLzmaProperties;
70
71
int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
72
73
#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
74
75
#define kLzmaNeedInitId (-2)
76
77
typedef struct _CLzmaDecoderState
78
{
79
  CLzmaProperties Properties;
80
  CProb *Probs;
81
82
  #ifdef _LZMA_IN_CB
83
  const unsigned char *Buffer;
84
  const unsigned char *BufferLim;
85
  #endif
86
87
  #ifdef _LZMA_OUT_READ
88
  unsigned char *Dictionary;
89
  UInt32 Range;
90
  UInt32 Code;
91
  UInt32 DictionaryPos;
92
  UInt32 GlobalPos;
93
  UInt32 DistanceLimit;
94
  UInt32 Reps[4];
95
  int State;
96
  int RemainLen;
97
  unsigned char TempDictionary[4];
98
  #endif
99
} CLzmaDecoderState;
100
101
#ifdef _LZMA_OUT_READ
102
#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
103
#endif
104
105
int LzmaDecode(CLzmaDecoderState *vs,
106
    #ifdef _LZMA_IN_CB
107
    ILzmaInCallback *inCallback,
108
    #else
109
    const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
110
    #endif
111
    unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
112
113
#endif
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/LzmaTypes.h (+45 lines)
Line 0 Link Here
1
/*
2
LzmaTypes.h
3
4
Types for LZMA Decoder
5
6
This file written and distributed to public domain by Igor Pavlov.
7
This file is part of LZMA SDK 4.40 (2006-05-01)
8
*/
9
10
#ifndef __LZMATYPES_H
11
#define __LZMATYPES_H
12
13
#ifndef _7ZIP_BYTE_DEFINED
14
#define _7ZIP_BYTE_DEFINED
15
typedef unsigned char Byte;
16
#endif
17
18
#ifndef _7ZIP_UINT16_DEFINED
19
#define _7ZIP_UINT16_DEFINED
20
typedef unsigned short UInt16;
21
#endif
22
23
#ifndef _7ZIP_UINT32_DEFINED
24
#define _7ZIP_UINT32_DEFINED
25
#ifdef _LZMA_UINT32_IS_ULONG
26
typedef unsigned long UInt32;
27
#else
28
typedef unsigned int UInt32;
29
#endif
30
#endif 
31
32
/* #define _LZMA_NO_SYSTEM_SIZE_T */
33
/* You can use it, if you don't want <stddef.h> */
34
35
#ifndef _7ZIP_SIZET_DEFINED
36
#define _7ZIP_SIZET_DEFINED
37
#ifdef _LZMA_NO_SYSTEM_SIZE_T
38
typedef UInt32 SizeT;
39
#else
40
#include <stddef.h>
41
typedef size_t SizeT;
42
#endif
43
#endif
44
45
#endif
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/Makefile (+16 lines)
Line 0 Link Here
1
2
# Copyright (C) 2006-2008 Junjiro Okajima
3
# Copyright (C) 2006-2008 Tomas Matejicek, slax.org
4
#
5
# LICENSE follows the described one in lzma.txt.
6
7
# $Id: Makefile,v 1.3 2008-03-12 01:49:39 jro Exp $
8
9
# # the environment variables are not inherited since 2.6.23
10
# ifdef SQLZMA_EXTRA_CFLAGS
11
# EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS}
12
# endif
13
14
obj-m += unlzma.o sqlzma.o
15
unlzma-y := module.o
16
sqlzma-y := uncomp.o
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/module.c (+36 lines)
Line 0 Link Here
1
2
/*
3
 * Copyright (C) 2006-2007 Junjiro Okajima
4
 * Copyright (C) 2006-2007 Tomas Matejicek, slax.org
5
 *
6
 * LICENSE follows the described one in lzma.txt.
7
 */
8
9
/* $Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $ */
10
11
#include <linux/init.h>
12
#include <linux/module.h>
13
14
#include "LzmaDecode.c"
15
16
EXPORT_SYMBOL(LzmaDecodeProperties);
17
EXPORT_SYMBOL(LzmaDecode);
18
19
#if 0
20
static int __init unlzma_init(void)
21
{
22
	return 0;
23
}
24
25
static void __exit unlzma_exit(void)
26
{
27
}
28
29
module_init(unlzma_init);
30
module_exit(unlzma_exit);
31
#endif
32
33
MODULE_LICENSE("GPL");
34
MODULE_VERSION("$Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $");
35
MODULE_DESCRIPTION("LZMA uncompress. "
36
		   "A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.");
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/sqlzma.h (+84 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2006-2008 Junjiro Okajima
3
 * Copyright (C) 2006-2008 Tomas Matejicek, slax.org
4
 *
5
 * LICENSE follows the described one in lzma.
6
 */
7
8
/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */
9
10
#ifndef __sqlzma_h__
11
#define __sqlzma_h__
12
13
#ifndef __KERNEL__
14
#include <stdlib.h>
15
#include <string.h>
16
#include <zlib.h>
17
#ifdef _REENTRANT
18
#include <pthread.h>
19
#endif
20
#else
21
#include <linux/zlib.h>
22
#endif
23
#define _7ZIP_BYTE_DEFINED
24
25
/*
26
 * detect the compression method automatically by the first byte of compressed
27
 * data.
28
 * according to rfc1950, the first byte of zlib compression must be 0x?8.
29
 */
30
#define is_lzma(c)	(c == 0x5d)
31
32
/* ---------------------------------------------------------------------- */
33
34
#ifdef __cplusplus
35
extern "C" {
36
#endif
37
38
#ifndef __KERNEL__
39
/* for mksquashfs only */
40
struct sqlzma_opts {
41
	unsigned int	try_lzma;
42
	unsigned int 	dicsize;
43
};
44
int sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in,
45
	      uInt avail_in, Bytef *next_out, uInt avail_out);
46
#endif
47
48
/* ---------------------------------------------------------------------- */
49
/*
50
 * Three patterns for sqlzma uncompression. very dirty code.
51
 * - kernel space (squashfs kernel module)
52
 * - user space with pthread (mksquashfs)
53
 * - user space without pthread (unsquashfs)
54
 */
55
56
struct sized_buf {
57
	unsigned int	sz;
58
	unsigned char	*buf;
59
};
60
61
enum {SQUN_PROB, SQUN_RESULT, SQUN_LAST};
62
struct sqlzma_un {
63
	int			un_lzma;
64
	struct sized_buf	un_a[SQUN_LAST];
65
	unsigned char           un_prob[31960]; /* unlzma 64KB - 1MB */
66
	z_stream		un_stream;
67
#define un_cmbuf	un_stream.next_in
68
#define un_cmlen	un_stream.avail_in
69
#define un_resbuf	un_stream.next_out
70
#define un_resroom	un_stream.avail_out
71
#define un_reslen	un_stream.total_out
72
};
73
74
int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz);
75
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
76
	      struct sized_buf *dst);
77
void sqlzma_fin(struct sqlzma_un *un);
78
79
/* ---------------------------------------------------------------------- */
80
81
#ifdef __cplusplus
82
};
83
#endif
84
#endif
(-)linux-2.6.25-gentoo-r8.orig/lib/lzma/uncomp.c (+223 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2006-2008 Junjiro Okajima
3
 * Copyright (C) 2006-2008 Tomas Matejicek, slax.org
4
 *
5
 * LICENSE follows the described one in lzma.txt.
6
 */
7
8
/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */
9
10
/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */
11
12
#ifndef __KERNEL__
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <string.h>
16
#include <errno.h>
17
#include <assert.h>
18
#include <pthread.h>
19
#define unlikely(x)		__builtin_expect(!!(x), 0)
20
#define BUG_ON(x)		assert(!(x))
21
/* sqlzma buffers are always larger than a page. true? */
22
#define kmalloc(sz,gfp)		malloc(sz)
23
#define kfree(p)		free(p)
24
#define zlib_inflate(s, f)	inflate(s, f)
25
#define zlib_inflateInit(s)	inflateInit(s)
26
#define zlib_inflateReset(s)	inflateReset(s)
27
#define zlib_inflateEnd(s)	inflateEnd(s)
28
#else
29
#include <linux/init.h>
30
#include <linux/module.h>
31
#include <linux/kernel.h>
32
#include <linux/vmalloc.h>
33
#ifndef WARN_ON_ONCE
34
#define WARN_ON_ONCE(b)	WARN_ON(b)
35
#endif
36
#endif /* __KERNEL__ */
37
38
#include "sqlzma.h"
39
#include "LzmaDecode.h"
40
41
static int LzmaUncompress(struct sqlzma_un *un)
42
{
43
	int err, i, ret;
44
	SizeT outSize, inProcessed, outProcessed, srclen;
45
	/* it's about 24-80 bytes structure, if int is 32-bit */
46
	CLzmaDecoderState state;
47
	unsigned char *dst, *src, a[8];
48
	struct sized_buf *sbuf;
49
50
	/* Decode LZMA properties and allocate memory */
51
	err = -EINVAL;
52
	src = (void *)un->un_cmbuf;
53
	ret = LzmaDecodeProperties(&state.Properties, src,
54
				   LZMA_PROPERTIES_SIZE);
55
	src += LZMA_PROPERTIES_SIZE;
56
	if (unlikely(ret != LZMA_RESULT_OK))
57
		goto out;
58
	i = LzmaGetNumProbs(&state.Properties);
59
	if (unlikely(i <= 0))
60
		i = 1;
61
	i *= sizeof(CProb);
62
	sbuf = un->un_a + SQUN_PROB;
63
	if (unlikely(sbuf->sz < i)) {
64
		if (sbuf->buf && sbuf->buf != un->un_prob)
65
			kfree(sbuf->buf);
66
#ifdef __KERNEL__
67
		printk("%s:%d: %d --> %d\n", __func__, __LINE__, sbuf->sz, i);
68
#else
69
		printf("%d --> %d\n", sbuf->sz, i);
70
#endif
71
		err = -ENOMEM;
72
		sbuf->sz = 0;
73
		sbuf->buf = kmalloc(i, GFP_ATOMIC);
74
		if (unlikely(!sbuf->buf))
75
			goto out;
76
		sbuf->sz = i;
77
	}
78
	state.Probs = (void *)sbuf->buf;
79
80
	/* Read uncompressed size */
81
	memcpy(a, src, sizeof(a));
82
	src += sizeof(a);
83
	outSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
84
85
	err = -EINVAL;
86
	dst = un->un_resbuf;
87
	if (unlikely(!dst || outSize > un->un_reslen))
88
		goto out;
89
	un->un_reslen = outSize;
90
	srclen = un->un_cmlen - (src - un->un_cmbuf);
91
92
	/* Decompress */
93
	err = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize,
94
			 &outProcessed);
95
	if (unlikely(err))
96
		err = -EINVAL;
97
98
 out:
99
#ifndef __KERNEL__
100
	if (err)
101
		fprintf(stderr, "err %d\n", err);
102
#endif
103
	return err;
104
}
105
106
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
107
	      struct sized_buf *dst)
108
{
109
	int err, by_lzma = 1;
110
	if (un->un_lzma && is_lzma(*src->buf)) {
111
		un->un_cmbuf = src->buf;
112
		un->un_cmlen = src->sz;
113
		un->un_resbuf = dst->buf;
114
		un->un_reslen = dst->sz;
115
116
		/* this library is thread-safe */
117
		err = LzmaUncompress(un);
118
		goto out;
119
	}
120
121
	by_lzma = 0;
122
	err = zlib_inflateReset(&un->un_stream);
123
	if (unlikely(err != Z_OK))
124
		goto out;
125
	un->un_stream.next_in = src->buf;
126
	un->un_stream.avail_in = src->sz;
127
	un->un_stream.next_out = dst->buf;
128
	un->un_stream.avail_out = dst->sz;
129
	err = zlib_inflate(&un->un_stream, Z_FINISH);
130
	if (err == Z_STREAM_END)
131
		err = 0;
132
133
 out:
134
	if (unlikely(err)) {
135
#ifdef __KERNEL__
136
		WARN_ON_ONCE(1);
137
#else
138
		char a[64] = "ZLIB ";
139
		if (by_lzma) {
140
			strcpy(a, "LZMA ");
141
#ifdef _REENTRANT
142
			strerror_r(err, a + 5, sizeof(a) - 5);
143
#else
144
			strncat(a, strerror(err), sizeof(a) - 5);
145
#endif
146
		} else
147
			strncat(a, zError(err), sizeof(a) - 5);
148
		fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
149
#endif
150
	}
151
	return err;
152
}
153
154
int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz)
155
{
156
	int err;
157
158
	err = -ENOMEM;
159
	un->un_lzma = do_lzma;
160
	memset(un->un_a, 0, sizeof(un->un_a));
161
	un->un_a[SQUN_PROB].buf = un->un_prob;
162
	un->un_a[SQUN_PROB].sz = sizeof(un->un_prob);
163
	if (res_sz) {
164
		un->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL);
165
		if (unlikely(!un->un_a[SQUN_RESULT].buf))
166
			return err;
167
		un->un_a[SQUN_RESULT].sz = res_sz;
168
	}
169
170
	un->un_stream.next_in = NULL;
171
	un->un_stream.avail_in = 0;
172
#ifdef __KERNEL__
173
	un->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(),
174
					  GFP_KERNEL);
175
	if (unlikely(!un->un_stream.workspace))
176
		return err;
177
#else
178
	un->un_stream.opaque = NULL;
179
	un->un_stream.zalloc = Z_NULL;
180
	un->un_stream.zfree = Z_NULL;
181
#endif
182
	err = zlib_inflateInit(&un->un_stream);
183
	if (unlikely(err == Z_MEM_ERROR))
184
		return -ENOMEM;
185
	BUG_ON(err);
186
	return err;
187
}
188
189
void sqlzma_fin(struct sqlzma_un *un)
190
{
191
	int i;
192
	for (i = 0; i < SQUN_LAST; i++)
193
		if (un->un_a[i].buf && un->un_a[i].buf != un->un_prob)
194
			kfree(un->un_a[i].buf);
195
	BUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK);
196
}
197
198
#ifdef __KERNEL__
199
EXPORT_SYMBOL(sqlzma_un);
200
EXPORT_SYMBOL(sqlzma_init);
201
EXPORT_SYMBOL(sqlzma_fin);
202
203
#if 0
204
static int __init sqlzma_init(void)
205
{
206
	return 0;
207
}
208
209
static void __exit sqlzma_exit(void)
210
{
211
}
212
213
module_init(sqlzma_init);
214
module_exit(sqlzma_exit);
215
#endif
216
217
MODULE_LICENSE("GPL");
218
MODULE_AUTHOR("Junjiro Okajima <sfjro at users dot sf dot net>");
219
MODULE_VERSION("$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $");
220
MODULE_DESCRIPTION("LZMA uncompress for squashfs. "
221
		   "Some functions for squashfs to support LZMA and "
222
		   "a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org.");
223
#endif
(-)linux-2.6.25-gentoo-r8.orig/lib/Makefile (+2 lines)
Lines 68-73 Link Here
68
obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
68
obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
69
obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
69
obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
70
70
71
obj-$(CONFIG_LZMA) += lzma/
72
71
lib-$(CONFIG_GENERIC_BUG) += bug.o
73
lib-$(CONFIG_GENERIC_BUG) += bug.o
72
74
73
hostprogs-y	:= gen_crc32table
75
hostprogs-y	:= gen_crc32table

Return to bug 207737