diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/inode.c linux-2.6.25.9/fs/squashfs/inode.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/inode.c 2008-07-04 15:24:31.000000000 -0400 +++ linux-2.6.25.9/fs/squashfs/inode.c 2008-07-02 17:18:42.000000000 -0400 @@ -1,7 +1,7 @@ /* * Squashfs - a compressed read only filesystem for Linux * - * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 * Phillip Lougher * * This program is free software; you can redistribute it and/or @@ -34,9 +34,35 @@ #include #include "squashfs.h" +#include "sqlzma.h" +#include "sqmagic.h" -int squashfs_cached_blks; +#undef KeepPreemptive +#if defined(CONFIG_PREEMPT) && !defined(UnsquashNoPreempt) +#define KeepPreemptive +#endif + +struct sqlzma { +#ifdef KeepPreemptive + struct mutex mtx; +#endif + unsigned char read_data[SQUASHFS_FILE_MAX_SIZE]; + struct sqlzma_un un; +}; +static DEFINE_PER_CPU(struct sqlzma *, sqlzma); +#define dpri(fmt, args...) /* printk("%s:%d: " fmt, __func__, __LINE__, ##args) */ +#define dpri_un(un) dpri("un{%d, {%d %p}, {%d %p}, {%d %p}}\n", \ + (un)->un_lzma, (un)->un_a[0].sz, (un)->un_a[0].buf, \ + (un)->un_a[1].sz, (un)->un_a[1].buf, \ + (un)->un_a[2].sz, (un)->un_a[2].buf) + +static int squashfs_cached_blks; + +static struct dentry *squashfs_fh_to_dentry(struct super_block *s, + struct fid *fid, int fh_len, int fh_type); +static struct dentry *squashfs_fh_to_parent(struct super_block *s, + struct fid *fid, int fh_len, int fh_type); static struct dentry *squashfs_get_parent(struct dentry *child); static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode); static int squashfs_statfs(struct dentry *, struct kstatfs *); @@ -77,14 +103,9 @@ .remount_fs = squashfs_remount }; -static struct super_operations squashfs_export_super_ops = { - .alloc_inode = squashfs_alloc_inode, - .destroy_inode = squashfs_destroy_inode, - .statfs = squashfs_statfs, - .put_super = squashfs_put_super, -}; - static struct export_operations squashfs_export_ops = { + .fh_to_dentry = squashfs_fh_to_dentry, + .fh_to_parent = squashfs_fh_to_parent, .get_parent = squashfs_get_parent }; @@ -241,35 +262,42 @@ } if (compressed) { - int zlib_err = 0; + int zlib_err = Z_STREAM_END; + int start; + enum {Src, Dst}; + struct sized_buf sbuf[2]; + struct sqlzma *percpu; + unsigned char *p; /* * uncompress block */ - mutex_lock(&msblk->read_data_mutex); - - msblk->stream.next_out = buffer; - msblk->stream.avail_out = srclength; - - for (bytes = 0; k < b; k++) { - avail_bytes = min(c_byte - bytes, msblk->devblksize - offset); + /* mutex_lock(&msblk->read_data_mutex); */ + start = k; + for (; k < b; k++) { wait_on_buffer(bh[k]); if (!buffer_uptodate(bh[k])) goto release_mutex; + } - msblk->stream.next_in = bh[k]->b_data + offset; - msblk->stream.avail_in = avail_bytes; + /* it disables preemption */ + percpu = get_cpu_var(sqlzma); +#ifdef KeepPreemptive + put_cpu_var(sqlzma); + mutex_lock(&percpu->mtx); +#endif + p = percpu->read_data; + k = start; + for (bytes = 0; k < b; k++) { + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset); if (k == 0) { - zlib_err = zlib_inflateInit(&msblk->stream); - if (zlib_err != Z_OK) { - ERROR("zlib_inflateInit returned unexpected result 0x%x," - " srclength %d\n", zlib_err, srclength); - goto release_mutex; - } - + /* + * keep this block structture to simplify the + * diff. + */ if (avail_bytes == 0) { offset = 0; brelse(bh[k]); @@ -277,30 +305,38 @@ } } - zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH); - if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) { - ERROR("zlib_inflate returned unexpected result 0x%x," - " srclength %d, avail_in %d, avail_out %d\n", zlib_err, - srclength, msblk->stream.avail_in, msblk->stream.avail_out); - goto release_mutex; - } + memcpy(p, bh[k]->b_data + offset, avail_bytes); + p += avail_bytes; +#if 0 + BUG_ON(percpu->read_data + sizeof(percpu->read_data) + < p); +#endif bytes += avail_bytes; offset = 0; brelse(bh[k]); } - if (zlib_err != Z_STREAM_END) - goto release_mutex; - - zlib_err = zlib_inflateEnd(&msblk->stream); - if (zlib_err != Z_OK) { - ERROR("zlib_inflateEnd returned unexpected result 0x%x," - " srclength %d\n", zlib_err, srclength); + sbuf[Src].buf = percpu->read_data; + sbuf[Src].sz = bytes; + sbuf[Dst].buf = buffer; + sbuf[Dst].sz = srclength; + dpri_un(&percpu->un); + dpri("src %d %p, dst %d %p\n", sbuf[Src].sz, sbuf[Src].buf, + sbuf[Dst].sz, sbuf[Dst].buf); + zlib_err = sqlzma_un(&percpu->un, sbuf + Src, sbuf + Dst); + bytes = percpu->un.un_reslen; + +#ifdef KeepPreemptive + mutex_unlock(&percpu->mtx); +#else + put_cpu_var(sqlzma); +#endif + if (unlikely(zlib_err)) { + dpri("zlib_err %d\n", zlib_err); goto release_mutex; } - bytes = msblk->stream.total_out; - mutex_unlock(&msblk->read_data_mutex); + /* mutex_unlock(&msblk->read_data_mutex); */ } else { int i; @@ -328,7 +364,7 @@ return bytes; release_mutex: - mutex_unlock(&msblk->read_data_mutex); + /* mutex_unlock(&msblk->read_data_mutex); */ block_release: for (; k < b; k++) @@ -628,30 +664,72 @@ out: return SQUASHFS_INVALID_BLK; } - -static struct dentry *squashfs_get_parent(struct dentry *child) + + +static struct dentry *squashfs_export_iget(struct super_block *s, + unsigned int inode_number) { - struct inode *i = child->d_inode; - struct inode *parent = iget_locked(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode); - struct dentry *rv; + squashfs_inode_t inode; + struct inode *i; + struct dentry *dentry; - TRACE("Entered squashfs_get_parent\n"); + TRACE("Entered squashfs_export_iget\n"); - if(parent == NULL) { - rv = ERR_PTR(-EACCES); - goto out; + inode = squashfs_inode_lookup(s, inode_number); + if(inode == SQUASHFS_INVALID_BLK) { + dentry = ERR_PTR(-ENOENT); + goto failure; } - rv = d_alloc_anon(parent); - if(rv == NULL) - rv = ERR_PTR(-ENOMEM); + i = squashfs_iget(s, inode, inode_number); + if(i == NULL) { + dentry = ERR_PTR(-EACCES); + goto failure; + } -out: - return rv; + dentry = d_alloc_anon(i); + if (dentry == NULL) { + iput(i); + dentry = ERR_PTR(-ENOMEM); + } + +failure: + return dentry; } - + +static struct dentry *squashfs_fh_to_dentry(struct super_block *s, + struct fid *fid, int fh_len, int fh_type) +{ + if((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) || + fh_len < 2) + return NULL; + + return squashfs_export_iget(s, fid->i32.ino); +} + + +static struct dentry *squashfs_fh_to_parent(struct super_block *s, + struct fid *fid, int fh_len, int fh_type) +{ + if(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4) + return NULL; + + return squashfs_export_iget(s, fid->i32.parent_ino); +} + + +static struct dentry *squashfs_get_parent(struct dentry *child) +{ + struct inode *i = child->d_inode; + + TRACE("Entered squashfs_get_parent\n"); + + return squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode); +} + + SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number) { @@ -1075,12 +1153,13 @@ { struct squashfs_sb_info *msblk; struct squashfs_super_block *sblk; - int i; + int i, err; char b[BDEVNAME_SIZE]; struct inode *root; TRACE("Entered squashfs_fill_superblock\n"); + err = -ENOMEM; s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL); if (s->s_fs_info == NULL) { ERROR("Failed to allocate superblock\n"); @@ -1088,17 +1167,12 @@ } msblk = s->s_fs_info; - msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize()); - if (msblk->stream.workspace == NULL) { - ERROR("Failed to allocate zlib workspace\n"); - goto failure; - } sblk = &msblk->sblk; msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE); msblk->devblksize_log2 = ffz(~msblk->devblksize); - mutex_init(&msblk->read_data_mutex); + /* mutex_init(&msblk->read_data_mutex); */ mutex_init(&msblk->read_page_mutex); mutex_init(&msblk->block_cache_mutex); mutex_init(&msblk->fragment_mutex); @@ -1110,6 +1184,7 @@ /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not * beyond filesystem end. As we're using squashfs_read_data to read sblk here, * first set sblk->bytes_used to a useful value */ + err = -EINVAL; sblk->bytes_used = sizeof(struct squashfs_super_block); if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START, sizeof(struct squashfs_super_block) | @@ -1119,21 +1194,36 @@ } /* Check it is a SQUASHFS superblock */ - if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) { - if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) { - struct squashfs_super_block ssblk; - - WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", - bdevname(s->s_bdev, b)); - - SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk); - memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block)); - msblk->swap = 1; - } else { - SERROR("Can't find a SQUASHFS superblock on %s\n", - bdevname(s->s_bdev, b)); - goto failed_mount; - } + s->s_magic = sblk->s_magic; + msblk->swap = 0; + dpri("magic 0x%x\n", sblk->s_magic); + switch (sblk->s_magic) { + struct squashfs_super_block ssblk; + + case SQUASHFS_MAGIC_SWAP: + /*FALLTHROUGH*/ + case SQUASHFS_MAGIC_LZMA_SWAP: + WARNING("Mounting a different endian SQUASHFS " + "filesystem on %s\n", bdevname(s->s_bdev, b)); + + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk); + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block)); + msblk->swap = 1; + /*FALLTHROUGH*/ + case SQUASHFS_MAGIC: + case SQUASHFS_MAGIC_LZMA: + break; + default: + SERROR("Can't find a SQUASHFS superblock on %s\n", + bdevname(s->s_bdev, b)); + goto failed_mount; + } + + { + struct sqlzma *p; + dpri("block_size %d, devblksize %d\n", + sblk->block_size, msblk->devblksize); + BUG_ON(sblk->block_size > sizeof(p->read_data)); } /* Check the MAJOR & MINOR versions */ @@ -1177,6 +1267,7 @@ goto failed_mount; /* Allocate read_page block */ + err = -ENOMEM; msblk->read_page = vmalloc(sblk->block_size); if (msblk->read_page == NULL) { ERROR("Failed to allocate read_page block\n"); @@ -1192,19 +1283,30 @@ } msblk->guid = msblk->uid + sblk->no_uids; + dpri("swap %d\n", msblk->swap); + err = -EINVAL; if (msblk->swap) { - unsigned int suid[sblk->no_uids + sblk->no_guids]; + unsigned int *suid; + + err = -ENOMEM; + suid = kmalloc(sizeof(*suid) * (sblk->no_uids + sblk->no_guids), + GFP_KERNEL); + if (unlikely(!suid)) + goto failed_mount; + err = -EINVAL; if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start, ((sblk->no_uids + sblk->no_guids) * sizeof(unsigned int)) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) { ERROR("unable to read uid/gid table\n"); + kfree(suid); goto failed_mount; } SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids + sblk->no_guids), (sizeof(unsigned int) * 8)); + kfree(suid); } else if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start, ((sblk->no_uids + sblk->no_guids) * @@ -1218,6 +1320,7 @@ if (sblk->s_major == 1 && squashfs_1_0_supported(msblk)) goto allocate_root; + err = -ENOMEM; msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL); if (msblk->fragment == NULL) { @@ -1243,13 +1346,15 @@ if (read_inode_lookup_table(s) == 0) goto failed_mount; - s->s_op = &squashfs_export_super_ops; s->s_export_op = &squashfs_export_ops; allocate_root: + dpri("alloate_root\n"); root = new_inode(s); - if ((msblk->read_inode)(root, sblk->root_inode) == 0) + if ((msblk->read_inode)(root, sblk->root_inode) == 0) { + iput(root); goto failed_mount; + } insert_inode_hash(root); s->s_root = d_alloc_root(root); @@ -1270,13 +1375,10 @@ vfree(msblk->read_page); kfree(msblk->block_cache); kfree(msblk->fragment_index_2); - vfree(msblk->stream.workspace); kfree(s->s_fs_info); s->s_fs_info = NULL; - return -EINVAL; - -failure: - return -ENOMEM; + failure: + return err; } @@ -1287,7 +1389,7 @@ TRACE("Entered squashfs_statfs\n"); - buf->f_type = SQUASHFS_MAGIC; + buf->f_type = sblk->s_magic; buf->f_bsize = sblk->block_size; buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1; buf->f_bfree = buf->f_bavail = 0; @@ -1449,15 +1551,21 @@ int block = 0; if (msblk->swap) { - char sblock_list[blocks << 2]; + char *sblock_list; + + sblock_list = kmalloc(blocks << 2, GFP_KERNEL); + if (unlikely(!sblock_list)) + goto failure; if (!squashfs_get_cached_block(s, sblock_list, *start_block, *offset, blocks << 2, start_block, offset)) { ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset); + kfree(sblock_list); goto failure; } SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks); + kfree(sblock_list); } else { if (!squashfs_get_cached_block(s, block_list, *start_block, *offset, blocks << 2, start_block, offset)) { @@ -2089,7 +2197,6 @@ kfree(sbi->fragment_index); kfree(sbi->fragment_index_2); kfree(sbi->meta_index); - vfree(sbi->stream.workspace); kfree(s->s_fs_info); s->s_fs_info = NULL; } @@ -2103,19 +2210,63 @@ mnt); } +static void free_sqlzma(void) +{ + int cpu; + struct sqlzma *p; + + for_each_online_cpu(cpu) { + p = per_cpu(sqlzma, cpu); + if (p) { +#ifdef KeepPreemptive + mutex_destroy(&p->mtx); +#endif + sqlzma_fin(&p->un); + kfree(p); + } + } +} static int __init init_squashfs_fs(void) { + struct sqlzma *p; + int cpu; int err = init_inodecache(); if (err) goto out; + for_each_online_cpu(cpu) { + dpri("%d: %p\n", cpu, per_cpu(sqlzma, cpu)); + err = -ENOMEM; + p = kmalloc(sizeof(struct sqlzma), GFP_KERNEL); + if (p) { +#ifdef KeepPreemptive + mutex_init(&p->mtx); +#endif + err = sqlzma_init(&p->un, 1, 0); + if (unlikely(err)) { + ERROR("Failed to intialize uncompress workspace\n"); + break; + } + per_cpu(sqlzma, cpu) = p; + err = 0; + } else + break; + } + if (unlikely(err)) { + free_sqlzma(); + goto out; + } + printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) " - "Phillip Lougher\n"); + "Phillip Lougher\n" + "squashfs: LZMA suppport for slax.org by jro\n"); err = register_filesystem(&squashfs_fs_type); - if (err) + if (err) { + free_sqlzma(); destroy_inodecache(); + } out: return err; @@ -2125,6 +2276,7 @@ static void __exit exit_squashfs_fs(void) { unregister_filesystem(&squashfs_fs_type); + free_sqlzma(); destroy_inodecache(); } @@ -2173,6 +2325,6 @@ module_init(init_squashfs_fs); module_exit(exit_squashfs_fs); -MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem"); -MODULE_AUTHOR("Phillip Lougher "); +MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem, and LZMA suppport for slax.org"); +MODULE_AUTHOR("Phillip Lougher , and LZMA suppport for slax.org by jro"); MODULE_LICENSE("GPL"); diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaDecode.c linux-2.6.25.9/fs/squashfs/LzmaDecode.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaDecode.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/LzmaDecode.c 2008-07-04 08:48:55.000000000 -0400 @@ -0,0 +1,584 @@ +/* + LzmaDecode.c + LZMA Decoder (optimized for Speed version) + + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this Code, expressly permits you to + statically or dynamically link your Code (or bind by name) to the + interfaces of this file without subjecting your linked Code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#include "LzmaDecode.h" + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*Buffer++) + +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \ + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }} + +#ifdef _LZMA_IN_CB + +#define RC_TEST { if (Buffer == BufferLim) \ + { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \ + BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }} + +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2 + +#else + +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; } + +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2 + +#endif + +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } + +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; + +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ + { UpdateBit0(p); mi <<= 1; A0; } else \ + { UpdateBit1(p); mi = (mi + mi) + 1; A1; } + +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) + +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \ + { int i = numLevels; res = 1; \ + do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ + res -= (1 << numLevels); } + + +#define kNumPosBitsMax 4 +#define kNumPosStatesMax (1 << kNumPosBitsMax) + +#define kLenNumLowBits 3 +#define kLenNumLowSymbols (1 << kLenNumLowBits) +#define kLenNumMidBits 3 +#define kLenNumMidSymbols (1 << kLenNumMidBits) +#define kLenNumHighBits 8 +#define kLenNumHighSymbols (1 << kLenNumHighBits) + +#define LenChoice 0 +#define LenChoice2 (LenChoice + 1) +#define LenLow (LenChoice2 + 1) +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) +#define kNumLenProbs (LenHigh + kLenNumHighSymbols) + + +#define kNumStates 12 +#define kNumLitStates 7 + +#define kStartPosModelIndex 4 +#define kEndPosModelIndex 14 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) + +#define kNumPosSlotBits 6 +#define kNumLenToPosStates 4 + +#define kNumAlignBits 4 +#define kAlignTableSize (1 << kNumAlignBits) + +#define kMatchMinLen 2 + +#define IsMatch 0 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) +#define IsRepG0 (IsRep + kNumStates) +#define IsRepG1 (IsRepG0 + kNumStates) +#define IsRepG2 (IsRepG1 + kNumStates) +#define IsRep0Long (IsRepG2 + kNumStates) +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) +#define LenCoder (Align + kAlignTableSize) +#define RepLenCoder (LenCoder + kNumLenProbs) +#define Literal (RepLenCoder + kNumLenProbs) + +#if Literal != LZMA_BASE_SIZE +StopCompilingDueBUG +#endif + +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size) +{ + unsigned char prop0; + if (size < LZMA_PROPERTIES_SIZE) + return LZMA_RESULT_DATA_ERROR; + prop0 = propsData[0]; + if (prop0 >= (9 * 5 * 5)) + return LZMA_RESULT_DATA_ERROR; + { + for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5)); + for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9); + propsRes->lc = prop0; + /* + unsigned char remainder = (unsigned char)(prop0 / 9); + propsRes->lc = prop0 % 9; + propsRes->pb = remainder / 5; + propsRes->lp = remainder % 5; + */ + } + + #ifdef _LZMA_OUT_READ + { + int i; + propsRes->DictionarySize = 0; + for (i = 0; i < 4; i++) + propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8); + if (propsRes->DictionarySize == 0) + propsRes->DictionarySize = 1; + } + #endif + return LZMA_RESULT_OK; +} + +#define kLzmaStreamWasFinishedId (-1) + +int LzmaDecode(CLzmaDecoderState *vs, + #ifdef _LZMA_IN_CB + ILzmaInCallback *InCallback, + #else + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, + #endif + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed) +{ + CProb *p = vs->Probs; + SizeT nowPos = 0; + Byte previousByte = 0; + UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1; + UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1; + int lc = vs->Properties.lc; + + #ifdef _LZMA_OUT_READ + + UInt32 Range = vs->Range; + UInt32 Code = vs->Code; + #ifdef _LZMA_IN_CB + const Byte *Buffer = vs->Buffer; + const Byte *BufferLim = vs->BufferLim; + #else + const Byte *Buffer = inStream; + const Byte *BufferLim = inStream + inSize; + #endif + int state = vs->State; + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; + int len = vs->RemainLen; + UInt32 globalPos = vs->GlobalPos; + UInt32 distanceLimit = vs->DistanceLimit; + + Byte *dictionary = vs->Dictionary; + UInt32 dictionarySize = vs->Properties.DictionarySize; + UInt32 dictionaryPos = vs->DictionaryPos; + + Byte tempDictionary[4]; + + #ifndef _LZMA_IN_CB + *inSizeProcessed = 0; + #endif + *outSizeProcessed = 0; + if (len == kLzmaStreamWasFinishedId) + return LZMA_RESULT_OK; + + if (dictionarySize == 0) + { + dictionary = tempDictionary; + dictionarySize = 1; + tempDictionary[0] = vs->TempDictionary[0]; + } + + if (len == kLzmaNeedInitId) + { + { + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); + UInt32 i; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + rep0 = rep1 = rep2 = rep3 = 1; + state = 0; + globalPos = 0; + distanceLimit = 0; + dictionaryPos = 0; + dictionary[dictionarySize - 1] = 0; + #ifdef _LZMA_IN_CB + RC_INIT; + #else + RC_INIT(inStream, inSize); + #endif + } + len = 0; + } + while(len != 0 && nowPos < outSize) + { + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + len--; + } + if (dictionaryPos == 0) + previousByte = dictionary[dictionarySize - 1]; + else + previousByte = dictionary[dictionaryPos - 1]; + + #else /* if !_LZMA_OUT_READ */ + + int state = 0; + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; + int len = 0; + const Byte *Buffer; + const Byte *BufferLim; + UInt32 Range; + UInt32 Code; + + #ifndef _LZMA_IN_CB + *inSizeProcessed = 0; + #endif + *outSizeProcessed = 0; + + { + UInt32 i; + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + } + + #ifdef _LZMA_IN_CB + RC_INIT; + #else + RC_INIT(inStream, inSize); + #endif + + #endif /* _LZMA_OUT_READ */ + + while(nowPos < outSize) + { + CProb *prob; + UInt32 bound; + int posState = (int)( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & posStateMask); + + prob = p + IsMatch + (state << kNumPosBitsMax) + posState; + IfBit0(prob) + { + int symbol = 1; + UpdateBit0(prob) + prob = p + Literal + (LZMA_LIT_SIZE * + ((( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & literalPosMask) << lc) + (previousByte >> (8 - lc)))); + + if (state >= kNumLitStates) + { + int matchByte; + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + matchByte = dictionary[pos]; + #else + matchByte = outStream[nowPos - rep0]; + #endif + do + { + int bit; + CProb *probLit; + matchByte <<= 1; + bit = (matchByte & 0x100); + probLit = prob + 0x100 + bit + symbol; + RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break) + } + while (symbol < 0x100); + } + while (symbol < 0x100) + { + CProb *probLit = prob + symbol; + RC_GET_BIT(probLit, symbol) + } + previousByte = (Byte)symbol; + + outStream[nowPos++] = previousByte; + #ifdef _LZMA_OUT_READ + if (distanceLimit < dictionarySize) + distanceLimit++; + + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #endif + if (state < 4) state = 0; + else if (state < 10) state -= 3; + else state -= 6; + } + else + { + UpdateBit1(prob); + prob = p + IsRep + state; + IfBit0(prob) + { + UpdateBit0(prob); + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + state = state < kNumLitStates ? 0 : 3; + prob = p + LenCoder; + } + else + { + UpdateBit1(prob); + prob = p + IsRepG0 + state; + IfBit0(prob) + { + UpdateBit0(prob); + prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState; + IfBit0(prob) + { + #ifdef _LZMA_OUT_READ + UInt32 pos; + #endif + UpdateBit0(prob); + + #ifdef _LZMA_OUT_READ + if (distanceLimit == 0) + #else + if (nowPos == 0) + #endif + return LZMA_RESULT_DATA_ERROR; + + state = state < kNumLitStates ? 9 : 11; + #ifdef _LZMA_OUT_READ + pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + outStream[nowPos++] = previousByte; + #ifdef _LZMA_OUT_READ + if (distanceLimit < dictionarySize) + distanceLimit++; + #endif + + continue; + } + else + { + UpdateBit1(prob); + } + } + else + { + UInt32 distance; + UpdateBit1(prob); + prob = p + IsRepG1 + state; + IfBit0(prob) + { + UpdateBit0(prob); + distance = rep1; + } + else + { + UpdateBit1(prob); + prob = p + IsRepG2 + state; + IfBit0(prob) + { + UpdateBit0(prob); + distance = rep2; + } + else + { + UpdateBit1(prob); + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + state = state < kNumLitStates ? 8 : 11; + prob = p + RepLenCoder; + } + { + int numBits, offset; + CProb *probLen = prob + LenChoice; + IfBit0(probLen) + { + UpdateBit0(probLen); + probLen = prob + LenLow + (posState << kLenNumLowBits); + offset = 0; + numBits = kLenNumLowBits; + } + else + { + UpdateBit1(probLen); + probLen = prob + LenChoice2; + IfBit0(probLen) + { + UpdateBit0(probLen); + probLen = prob + LenMid + (posState << kLenNumMidBits); + offset = kLenNumLowSymbols; + numBits = kLenNumMidBits; + } + else + { + UpdateBit1(probLen); + probLen = prob + LenHigh; + offset = kLenNumLowSymbols + kLenNumMidSymbols; + numBits = kLenNumHighBits; + } + } + RangeDecoderBitTreeDecode(probLen, numBits, len); + len += offset; + } + + if (state < 4) + { + int posSlot; + state += kNumLitStates; + prob = p + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << + kNumPosSlotBits); + RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot); + if (posSlot >= kStartPosModelIndex) + { + int numDirectBits = ((posSlot >> 1) - 1); + rep0 = (2 | ((UInt32)posSlot & 1)); + if (posSlot < kEndPosModelIndex) + { + rep0 <<= numDirectBits; + prob = p + SpecPos + rep0 - posSlot - 1; + } + else + { + numDirectBits -= kNumAlignBits; + do + { + RC_NORMALIZE + Range >>= 1; + rep0 <<= 1; + if (Code >= Range) + { + Code -= Range; + rep0 |= 1; + } + } + while (--numDirectBits != 0); + prob = p + Align; + rep0 <<= kNumAlignBits; + numDirectBits = kNumAlignBits; + } + { + int i = 1; + int mi = 1; + do + { + CProb *prob3 = prob + mi; + RC_GET_BIT2(prob3, mi, ; , rep0 |= i); + i <<= 1; + } + while(--numDirectBits != 0); + } + } + else + rep0 = posSlot; + if (++rep0 == (UInt32)(0)) + { + /* it's for stream version */ + len = kLzmaStreamWasFinishedId; + break; + } + } + + len += kMatchMinLen; + #ifdef _LZMA_OUT_READ + if (rep0 > distanceLimit) + #else + if (rep0 > nowPos) + #endif + return LZMA_RESULT_DATA_ERROR; + + #ifdef _LZMA_OUT_READ + if (dictionarySize - distanceLimit > (UInt32)len) + distanceLimit += len; + else + distanceLimit = dictionarySize; + #endif + + do + { + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + len--; + outStream[nowPos++] = previousByte; + } + while(len != 0 && nowPos < outSize); + } + } + RC_NORMALIZE; + + #ifdef _LZMA_OUT_READ + vs->Range = Range; + vs->Code = Code; + vs->DictionaryPos = dictionaryPos; + vs->GlobalPos = globalPos + (UInt32)nowPos; + vs->DistanceLimit = distanceLimit; + vs->Reps[0] = rep0; + vs->Reps[1] = rep1; + vs->Reps[2] = rep2; + vs->Reps[3] = rep3; + vs->State = state; + vs->RemainLen = len; + vs->TempDictionary[0] = tempDictionary[0]; + #endif + + #ifdef _LZMA_IN_CB + vs->Buffer = Buffer; + vs->BufferLim = BufferLim; + #else + *inSizeProcessed = (SizeT)(Buffer - inStream); + #endif + *outSizeProcessed = nowPos; + return LZMA_RESULT_OK; +} diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaDecode.h linux-2.6.25.9/fs/squashfs/LzmaDecode.h --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaDecode.h 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/LzmaDecode.h 2008-07-04 08:49:12.000000000 -0400 @@ -0,0 +1,113 @@ +/* + LzmaDecode.h + LZMA Decoder interface + + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this code, expressly permits you to + statically or dynamically link your code (or bind by name) to the + interfaces of this file without subjecting your linked code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#ifndef __LZMADECODE_H +#define __LZMADECODE_H + +#include "LzmaTypes.h" + +/* #define _LZMA_IN_CB */ +/* Use callback for input data */ + +/* #define _LZMA_OUT_READ */ +/* Use read function for output data */ + +/* #define _LZMA_PROB32 */ +/* It can increase speed on some 32-bit CPUs, + but memory usage will be doubled in that case */ + +/* #define _LZMA_LOC_OPT */ +/* Enable local speed optimizations inside code */ + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb UInt16 +#endif + +#define LZMA_RESULT_OK 0 +#define LZMA_RESULT_DATA_ERROR 1 + +#ifdef _LZMA_IN_CB +typedef struct _ILzmaInCallback +{ + int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize); +} ILzmaInCallback; +#endif + +#define LZMA_BASE_SIZE 1846 +#define LZMA_LIT_SIZE 768 + +#define LZMA_PROPERTIES_SIZE 5 + +typedef struct _CLzmaProperties +{ + int lc; + int lp; + int pb; + #ifdef _LZMA_OUT_READ + UInt32 DictionarySize; + #endif +}CLzmaProperties; + +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size); + +#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp))) + +#define kLzmaNeedInitId (-2) + +typedef struct _CLzmaDecoderState +{ + CLzmaProperties Properties; + CProb *Probs; + + #ifdef _LZMA_IN_CB + const unsigned char *Buffer; + const unsigned char *BufferLim; + #endif + + #ifdef _LZMA_OUT_READ + unsigned char *Dictionary; + UInt32 Range; + UInt32 Code; + UInt32 DictionaryPos; + UInt32 GlobalPos; + UInt32 DistanceLimit; + UInt32 Reps[4]; + int State; + int RemainLen; + unsigned char TempDictionary[4]; + #endif +} CLzmaDecoderState; + +#ifdef _LZMA_OUT_READ +#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; } +#endif + +int LzmaDecode(CLzmaDecoderState *vs, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, + #endif + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed); + +#endif diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaTypes.h linux-2.6.25.9/fs/squashfs/LzmaTypes.h --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/LzmaTypes.h 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/LzmaTypes.h 2008-07-04 08:49:25.000000000 -0400 @@ -0,0 +1,45 @@ +/* +LzmaTypes.h + +Types for LZMA Decoder + +This file written and distributed to public domain by Igor Pavlov. +This file is part of LZMA SDK 4.40 (2006-05-01) +*/ + +#ifndef __LZMATYPES_H +#define __LZMATYPES_H + +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED +typedef unsigned char Byte; +#endif + +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED +typedef unsigned short UInt16; +#endif + +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED +#ifdef _LZMA_UINT32_IS_ULONG +typedef unsigned long UInt32; +#else +typedef unsigned int UInt32; +#endif +#endif + +/* #define _LZMA_NO_SYSTEM_SIZE_T */ +/* You can use it, if you don't want */ + +#ifndef _7ZIP_SIZET_DEFINED +#define _7ZIP_SIZET_DEFINED +#ifdef _LZMA_NO_SYSTEM_SIZE_T +typedef UInt32 SizeT; +#else +#include +typedef size_t SizeT; +#endif +#endif + +#endif diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/Makefile linux-2.6.25.9/fs/squashfs/Makefile --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/Makefile 2008-07-04 15:24:31.000000000 -0400 +++ linux-2.6.25.9/fs/squashfs/Makefile 2008-07-04 14:48:36.000000000 -0400 @@ -2,6 +2,16 @@ # Makefile for the linux squashfs routines. # -obj-$(CONFIG_SQUASHFS) += squashfs.o +# the environment variables are not inherited since 2.6.23 +ifdef SQLZMA_EXTRA_CFLAGS +EXTRA_CFLAGS += ${SQLZMA_EXTRA_CFLAGS} +endif + +obj-$(CONFIG_SQUASHFS) += squashfs.o sqlzma.o unlzma.o squashfs-y += inode.o squashfs-y += squashfs2_0.o + +sqlzma-y += uncomp.o sqlzmamod.o + +unlzma-y += module.o unlzmamod.o + diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/module.c linux-2.6.25.9/fs/squashfs/module.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/module.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/module.c 2008-07-03 22:01:29.000000000 -0400 @@ -0,0 +1,37 @@ + +/* + * Copyright (C) 2006-2007 Junjiro Okajima + * Copyright (C) 2006-2007 Tomas Matejicek, slax.org + * + * LICENSE follows the described one in lzma.txt. + */ + +/* $Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $ */ + +#include +#include + +//#include "../LzmaDecode.c" +#include "LzmaDecode.c" + +EXPORT_SYMBOL(LzmaDecodeProperties); +EXPORT_SYMBOL(LzmaDecode); + +#if 0 +static int __init unlzma_init(void) +{ + return 0; +} + +static void __exit unlzma_exit(void) +{ +} + +module_init(unlzma_init); +module_exit(unlzma_exit); +#endif + +MODULE_LICENSE("GPL"); +MODULE_VERSION("$Id: module.c,v 1.1 2007-11-05 05:43:36 jro Exp $"); +MODULE_DESCRIPTION("LZMA uncompress. " + "A tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org."); diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqlzma.h linux-2.6.25.9/fs/squashfs/sqlzma.h --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqlzma.h 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/sqlzma.h 2008-07-03 18:57:35.000000000 -0400 @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2006-2008 Junjiro Okajima + * Copyright (C) 2006-2008 Tomas Matejicek, slax.org + * + * LICENSE follows the described one in lzma. + */ + +/* $Id: sqlzma.h,v 1.20 2008-03-12 16:58:34 jro Exp $ */ + +#ifndef __sqlzma_h__ +#define __sqlzma_h__ + +#ifndef __KERNEL__ +#include +#include +#include +#ifdef _REENTRANT +#include +#endif +#else +#include +#endif +#define _7ZIP_BYTE_DEFINED + +/* + * detect the compression method automatically by the first byte of compressed + * data. + * according to rfc1950, the first byte of zlib compression must be 0x?8. + */ +#define is_lzma(c) (c == 0x5d) + +/* ---------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __KERNEL__ +/* for mksquashfs only */ +struct sqlzma_opts { + unsigned int try_lzma; + unsigned int dicsize; +}; +int sqlzma_cm(struct sqlzma_opts *opts, z_stream *stream, Bytef *next_in, + uInt avail_in, Bytef *next_out, uInt avail_out); +#endif + +/* ---------------------------------------------------------------------- */ +/* + * Three patterns for sqlzma uncompression. very dirty code. + * - kernel space (squashfs kernel module) + * - user space with pthread (mksquashfs) + * - user space without pthread (unsquashfs) + */ + +struct sized_buf { + unsigned int sz; + unsigned char *buf; +}; + +enum {SQUN_PROB, SQUN_RESULT, SQUN_LAST}; +struct sqlzma_un { + int un_lzma; + struct sized_buf un_a[SQUN_LAST]; + unsigned char un_prob[31960]; /* unlzma 64KB - 1MB */ + z_stream un_stream; +#define un_cmbuf un_stream.next_in +#define un_cmlen un_stream.avail_in +#define un_resbuf un_stream.next_out +#define un_resroom un_stream.avail_out +#define un_reslen un_stream.total_out +}; + +int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz); +int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, + struct sized_buf *dst); +void sqlzma_fin(struct sqlzma_un *un); + +/* ---------------------------------------------------------------------- */ + +#ifdef __cplusplus +}; +#endif +#endif diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqlzmamod.c linux-2.6.25.9/fs/squashfs/sqlzmamod.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqlzmamod.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/sqlzmamod.c 2008-07-03 22:12:06.000000000 -0400 @@ -0,0 +1,19 @@ +#include +#include +#include + +MODULE_INFO(vermagic, VERMAGIC_STRING); + +struct module __this_module +__attribute__((section(".gnu.linkonce.this_module"))) = { + .name = KBUILD_MODNAME, + .arch = MODULE_ARCH_INIT, +}; + +static const char __module_depends[] +__used +__attribute__((section(".modinfo"))) = +"depends=unlzma"; + + +MODULE_INFO(srcversion, "158C234A8910D06367C463B"); diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqmagic.h linux-2.6.25.9/fs/squashfs/sqmagic.h --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/sqmagic.h 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/sqmagic.h 2008-07-03 18:58:31.000000000 -0400 @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2006 Junjiro Okajima + * Copyright (C) 2006 Tomas Matejicek, slax.org + * + * LICENSE must follow the one in squashfs. + */ + +/* $Id: sqmagic.h,v 1.2 2006-11-27 03:54:58 jro Exp $ */ + +#ifndef __sqmagic_h__ +#define __sqmagic_h__ + +/* see SQUASHFS_MAGIC in squashfs_fs.h */ +#define SQUASHFS_MAGIC_LZMA 0x71736873 +#define SQUASHFS_MAGIC_LZMA_SWAP 0x73687371 + +#endif diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/squashfsmod.c linux-2.6.25.9/fs/squashfs/squashfsmod.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/squashfsmod.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/squashfsmod.c 2008-07-03 22:01:50.000000000 -0400 @@ -0,0 +1,23 @@ +#include +#include +#include + +MODULE_INFO(vermagic, VERMAGIC_STRING); + +struct module __this_module +__attribute__((section(".gnu.linkonce.this_module"))) = { + .name = KBUILD_MODNAME, + .init = init_module, +#ifdef CONFIG_MODULE_UNLOAD + .exit = cleanup_module, +#endif + .arch = MODULE_ARCH_INIT, +}; + +static const char __module_depends[] +__used +__attribute__((section(".modinfo"))) = +"depends=sqlzma"; + + +MODULE_INFO(srcversion, "CF2A160AB4A0ECD1E3D30B3"); diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/uncomp.c linux-2.6.25.9/fs/squashfs/uncomp.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/uncomp.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/uncomp.c 2008-07-03 22:01:30.000000000 -0400 @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2006-2008 Junjiro Okajima + * Copyright (C) 2006-2008 Tomas Matejicek, slax.org + * + * LICENSE follows the described one in lzma.txt. + */ + +/* $Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $ */ + +/* extract some parts from lzma443/C/7zip/Compress/LZMA_C/LzmaTest.c */ + +#ifndef __KERNEL__ +#include +#include +#include +#include +#include +#include +#define unlikely(x) __builtin_expect(!!(x), 0) +#define BUG_ON(x) assert(!(x)) +/* sqlzma buffers are always larger than a page. true? */ +#define kmalloc(sz,gfp) malloc(sz) +#define kfree(p) free(p) +#define zlib_inflate(s, f) inflate(s, f) +#define zlib_inflateInit(s) inflateInit(s) +#define zlib_inflateReset(s) inflateReset(s) +#define zlib_inflateEnd(s) inflateEnd(s) +#else +#include +#include +#include +#include +#ifndef WARN_ON_ONCE +#define WARN_ON_ONCE(b) WARN_ON(b) +#endif +#endif /* __KERNEL__ */ + +#include "sqlzma.h" +#include "LzmaDecode.h" + +static int LzmaUncompress(struct sqlzma_un *un) +{ + int err, i, ret; + SizeT outSize, inProcessed, outProcessed, srclen; + /* it's about 24-80 bytes structure, if int is 32-bit */ + CLzmaDecoderState state; + unsigned char *dst, *src, a[8]; + struct sized_buf *sbuf; + + /* Decode LZMA properties and allocate memory */ + err = -EINVAL; + src = (void *)un->un_cmbuf; + ret = LzmaDecodeProperties(&state.Properties, src, + LZMA_PROPERTIES_SIZE); + src += LZMA_PROPERTIES_SIZE; + if (unlikely(ret != LZMA_RESULT_OK)) + goto out; + i = LzmaGetNumProbs(&state.Properties); + if (unlikely(i <= 0)) + i = 1; + i *= sizeof(CProb); + sbuf = un->un_a + SQUN_PROB; + if (unlikely(sbuf->sz < i)) { + if (sbuf->buf && sbuf->buf != un->un_prob) + kfree(sbuf->buf); +#ifdef __KERNEL__ + printk("%s:%d: %d --> %d\n", __func__, __LINE__, sbuf->sz, i); +#else + printf("%d --> %d\n", sbuf->sz, i); +#endif + err = -ENOMEM; + sbuf->sz = 0; + sbuf->buf = kmalloc(i, GFP_ATOMIC); + if (unlikely(!sbuf->buf)) + goto out; + sbuf->sz = i; + } + state.Probs = (void *)sbuf->buf; + + /* Read uncompressed size */ + memcpy(a, src, sizeof(a)); + src += sizeof(a); + outSize = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24); + + err = -EINVAL; + dst = un->un_resbuf; + if (unlikely(!dst || outSize > un->un_reslen)) + goto out; + un->un_reslen = outSize; + srclen = un->un_cmlen - (src - un->un_cmbuf); + + /* Decompress */ + err = LzmaDecode(&state, src, srclen, &inProcessed, dst, outSize, + &outProcessed); + if (unlikely(err)) + err = -EINVAL; + + out: +#ifndef __KERNEL__ + if (err) + fprintf(stderr, "err %d\n", err); +#endif + return err; +} + +int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, + struct sized_buf *dst) +{ + int err, by_lzma = 1; + if (un->un_lzma && is_lzma(*src->buf)) { + un->un_cmbuf = src->buf; + un->un_cmlen = src->sz; + un->un_resbuf = dst->buf; + un->un_reslen = dst->sz; + + /* this library is thread-safe */ + err = LzmaUncompress(un); + goto out; + } + + by_lzma = 0; + err = zlib_inflateReset(&un->un_stream); + if (unlikely(err != Z_OK)) + goto out; + un->un_stream.next_in = src->buf; + un->un_stream.avail_in = src->sz; + un->un_stream.next_out = dst->buf; + un->un_stream.avail_out = dst->sz; + err = zlib_inflate(&un->un_stream, Z_FINISH); + if (err == Z_STREAM_END) + err = 0; + + out: + if (unlikely(err)) { +#ifdef __KERNEL__ + WARN_ON_ONCE(1); +#else + char a[64] = "ZLIB "; + if (by_lzma) { + strcpy(a, "LZMA "); +#ifdef _REENTRANT + strerror_r(err, a + 5, sizeof(a) - 5); +#else + strncat(a, strerror(err), sizeof(a) - 5); +#endif + } else + strncat(a, zError(err), sizeof(a) - 5); + fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a); +#endif + } + return err; +} + +int sqlzma_init(struct sqlzma_un *un, int do_lzma, unsigned int res_sz) +{ + int err; + + err = -ENOMEM; + un->un_lzma = do_lzma; + memset(un->un_a, 0, sizeof(un->un_a)); + un->un_a[SQUN_PROB].buf = un->un_prob; + un->un_a[SQUN_PROB].sz = sizeof(un->un_prob); + if (res_sz) { + un->un_a[SQUN_RESULT].buf = kmalloc(res_sz, GFP_KERNEL); + if (unlikely(!un->un_a[SQUN_RESULT].buf)) + return err; + un->un_a[SQUN_RESULT].sz = res_sz; + } + + un->un_stream.next_in = NULL; + un->un_stream.avail_in = 0; +#ifdef __KERNEL__ + un->un_stream.workspace = kmalloc(zlib_inflate_workspacesize(), + GFP_KERNEL); + if (unlikely(!un->un_stream.workspace)) + return err; +#else + un->un_stream.opaque = NULL; + un->un_stream.zalloc = Z_NULL; + un->un_stream.zfree = Z_NULL; +#endif + err = zlib_inflateInit(&un->un_stream); + if (unlikely(err == Z_MEM_ERROR)) + return -ENOMEM; + BUG_ON(err); + return err; +} + +void sqlzma_fin(struct sqlzma_un *un) +{ + int i; + for (i = 0; i < SQUN_LAST; i++) + if (un->un_a[i].buf && un->un_a[i].buf != un->un_prob) + kfree(un->un_a[i].buf); + BUG_ON(zlib_inflateEnd(&un->un_stream) != Z_OK); +} + +#ifdef __KERNEL__ +EXPORT_SYMBOL(sqlzma_un); +EXPORT_SYMBOL(sqlzma_init); +EXPORT_SYMBOL(sqlzma_fin); + +#if 0 +static int __init sqlzma_init(void) +{ + return 0; +} + +static void __exit sqlzma_exit(void) +{ +} + +module_init(sqlzma_init); +module_exit(sqlzma_exit); +#endif + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Junjiro Okajima "); +MODULE_VERSION("$Id: uncomp.c,v 1.7 2008-03-12 16:58:34 jro Exp $"); +MODULE_DESCRIPTION("LZMA uncompress for squashfs. " + "Some functions for squashfs to support LZMA and " + "a tiny wrapper for LzmaDecode.c in LZMA SDK from www.7-zip.org."); +#endif diff -ruN /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/unlzmamod.c linux-2.6.25.9/fs/squashfs/unlzmamod.c --- /root/rpmbuild/BUILD/kernel-2.6.25/linux-2.6.25.i686/fs/squashfs/unlzmamod.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2.6.25.9/fs/squashfs/unlzmamod.c 2008-07-03 22:12:06.000000000 -0400 @@ -0,0 +1,19 @@ +#include +#include +#include + +MODULE_INFO(vermagic, VERMAGIC_STRING); + +struct module __this_module +__attribute__((section(".gnu.linkonce.this_module"))) = { + .name = KBUILD_MODNAME, + .arch = MODULE_ARCH_INIT, +}; + +static const char __module_depends[] +__used +__attribute__((section(".modinfo"))) = +"depends="; + + +MODULE_INFO(srcversion, "6D476492862EDD0A10871CE");